semanage command not found in CentOS 7 / 6 & RHEL 7 / 6 – Quick Fix

When I was drafting an article about the installation of MongoDB on CentOS, I had to run semanage command to make a change in SELinux policy to allow us access to MongoDB on port 27017.
semanage port -a -t mongod_port_t -p tcp 27017
To my surprise, I got an error.
-bash: semanage: command not found
semanage is used to configure certain parts of SELinux policy without requiring modification to or recompilation from policy sources.
This small post will help you to install the necessary packages for getting semanage command. Let us see which package provides us ifconfig command using the YUM command.
yum whatprovides semanage
OR
yum provides *bin/semanage
Output:
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.iitm.ac.in * extras: ftp.iitm.ac.in * updates: ftp.iitm.ac.in base/7/x86_64/filelists_db | 6.7 MB 00:00:01 extras/7/x86_64/filelists_db | 528 kB 00:00:00 nginx/x86_64/filelists_db | 39 kB 00:00:00 updates/7/x86_64/filelists_db | 3.1 MB 00:00:00 policycoreutils-python-2.5-17.1.el7.x86_64 : SELinux policy core python utilities Repo : base Matched from: Filename : /usr/sbin/semanage

From the above command output, you can see that policycoreutils-python package provides you semanage command. Now, install the policycoreutils-python package using the YUM command.
yum -y install policycoreutils-python
Output:
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.iitm.ac.in * extras: ftp.iitm.ac.in * updates: ftp.iitm.ac.in Resolving Dependencies --> Running transaction check ---> Package policycoreutils-python.x86_64 0:2.5-17.1.el7 will be installed --> Processing Dependency: setools-libs >= 3.3.8-1 for package: policycoreutils-python-2.5-17.1.el7.x86_64 --> Processing Dependency: libsemanage-python >= 2.5-5 for package: policycoreutils-python-2.5-17.1.el7.x86_64 --> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-17.1.el7.x86_64 --> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-17.1.el7.x86_64 --> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-17.1.el7.x86_64 --> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-17.1.el7.x86_64 --> Processing Dependency: libcgroup for package: policycoreutils-python-2.5-17.1.el7.x86_64 --> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-17.1.el7.x86_64 --> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-17.1.el7.x86_64 --> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-17.1.el7.x86_64 --> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-17.1.el7.x86_64 --> Running transaction check ---> Package audit-libs-python.x86_64 0:2.7.6-3.el7 will be installed ---> Package checkpolicy.x86_64 0:2.5-4.el7 will be installed ---> Package libcgroup.x86_64 0:0.41-13.el7 will be installed ---> Package libsemanage-python.x86_64 0:2.5-8.el7 will be installed ---> Package python-IPy.noarch 0:0.75-6.el7 will be installed ---> Package setools-libs.x86_64 0:3.3.8-1.1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved =========================================================================================================== Package Arch Version Repository Size =========================================================================================================== Installing: policycoreutils-python x86_64 2.5-17.1.el7 base 446 k Installing for dependencies: audit-libs-python x86_64 2.7.6-3.el7 base 73 k checkpolicy x86_64 2.5-4.el7 base 290 k libcgroup x86_64 0.41-13.el7 base 65 k libsemanage-python x86_64 2.5-8.el7 base 104 k python-IPy noarch 0.75-6.el7 base 32 k setools-libs x86_64 3.3.8-1.1.el7 base 612 k Transaction Summary =========================================================================================================== Install 1 Package (+6 Dependent packages) Total download size: 1.6 M Installed size: 5.1 M Downloading packages: (1/7): audit-libs-python-2.7.6-3.el7.x86_64.rpm | 73 kB 00:00:00 (2/7): libsemanage-python-2.5-8.el7.x86_64.rpm | 104 kB 00:00:00 (3/7): python-IPy-0.75-6.el7.noarch.rpm | 32 kB 00:00:00 (4/7): checkpolicy-2.5-4.el7.x86_64.rpm | 290 kB 00:00:00 (5/7): setools-libs-3.3.8-1.1.el7.x86_64.rpm | 612 kB 00:00:00 (6/7): policycoreutils-python-2.5-17.1.el7.x86_64.rpm | 446 kB 00:00:00 (7/7): libcgroup-0.41-13.el7.x86_64.rpm | 65 kB 00:00:01 ----------------------------------------------------------------------------------------------------------- Total 1.4 MB/s | 1.6 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : setools-libs-3.3.8-1.1.el7.x86_64 1/7 Installing : checkpolicy-2.5-4.el7.x86_64 2/7 Installing : libcgroup-0.41-13.el7.x86_64 3/7 Installing : python-IPy-0.75-6.el7.noarch 4/7 Installing : audit-libs-python-2.7.6-3.el7.x86_64 5/7 Installing : libsemanage-python-2.5-8.el7.x86_64 6/7 Installing : policycoreutils-python-2.5-17.1.el7.x86_64 7/7 Verifying : libsemanage-python-2.5-8.el7.x86_64 1/7 Verifying : audit-libs-python-2.7.6-3.el7.x86_64 2/7 Verifying : python-IPy-0.75-6.el7.noarch 3/7 Verifying : policycoreutils-python-2.5-17.1.el7.x86_64 4/7 Verifying : libcgroup-0.41-13.el7.x86_64 5/7 Verifying : checkpolicy-2.5-4.el7.x86_64 6/7 Verifying : setools-libs-3.3.8-1.1.el7.x86_64 7/7 Installed: policycoreutils-python.x86_64 0:2.5-17.1.el7 Dependency Installed: audit-libs-python.x86_64 0:2.7.6-3.el7 checkpolicy.x86_64 0:2.5-4.el7 libcgroup.x86_64 0:0.41-13.el7 libsemanage-python.x86_64 0:2.5-8.el7 python-IPy.noarch 0:0.75-6.el7 setools-libs.x86_64 0:3.3.8-1.1.el7 Complete!
Once the installation is complete, run semanage to see whether it is available or not.
semanage port -a -t mongod_port_t -p tcp 27017
Now, you should not see any errors.
That’s All.