Presentation
When installing and removing packages, it is very easy to get a system cluttered after some time.
For example, install the httpd package and then remove it.
At first, 5 packages are installed because the httpd package comes with 4 other packages as dependencies.
# yum install -y httpd Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile Resolving Dependencies ... ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: httpd x86_64 2.4.6-17.el7.centos.1 base 2.7 M Installing for dependencies: apr x86_64 1.4.8-3.el7 base 103 k apr-util x86_64 1.5.2-6.el7 base 92 k httpd-tools x86_64 2.4.6-17.el7.centos.1 base 77 k mailcap noarch 2.1.41-2.el7 base 31 k Transaction Summary ================================================================================ Install 1 Package (+4 Dependent packages) ... Complete!
Then, remove the httpd package, only one package is removed!
# yum remove -y httpd Loaded plugins: fastestmirror, langpacks Resolving Dependencies ... ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: httpd x86_64 2.4.6-17.el7.centos.1 @base 9.3 M Transaction Summary ================================================================================ Remove 1 Package ... Complete!
Solutions
There are at least two solutions to this problem.
You can use the yum autoremove command after each removal.
# yum autoremove -y Loaded plugins: fastestmirror, langpacks Resolving Dependencies ... ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: httpd-tools x86_64 2.4.6-17.el7.centos.1 @base 168 k mailcap noarch 2.1.41-2.el7 @base 62 k Removing for dependencies: apr x86_64 1.4.8-3.el7 @base 221 k apr-util x86_64 1.5.2-6.el7 @base 194 k Transaction Summary ================================================================================ Remove 2 Packages (+2 Dependent packages) ... Complete!
A more transparent solution and less prone to oversight is to paste the following line into the /etc/yum.conf file:
clean_requirements_on_remove=1
So, when you remove a package (here httpd), you get the package and all of its dependencies removed:
# yum remove httpd -y Loaded plugins: fastestmirror, langpacks Resolving Dependencies ... ================================================================================ Package Arch Version Repository Size ================================================================================ Removing: httpd x86_64 2.4.6-17.el7.centos.1 @base 9.3 M Removing for dependencies: apr x86_64 1.4.8-3.el7 @base 221 k apr-util x86_64 1.5.2-6.el7 @base 194 k httpd-tools x86_64 2.4.6-17.el7.centos.1 @base 168 k mailcap noarch 2.1.41-2.el7 @base 62 k Transaction Summary ================================================================================ Remove 1 Package (+4 Dependent packages) ... Complete!
Going further
The two previous solutions are perfectly safe. You don’t risk removing packages you don’t want to.
However, it is possible to go further and remove unneeded packages in your system but you need to take extra precautions.
To get the list of unneeded packages, type:
# package-cleanup --leaves Loaded plugins: fastestmirror, langpacks libertas-sd8686-firmware-20140213-0.3.git4164c23.el7.noarch libertas-sd8787-firmware-20140213-0.3.git4164c23.el7.noarch libertas-usb8388-firmware-20140213-0.3.git4164c23.el7.noarch libreport-plugin-mailx-2.1.11-10.el7.centos.x86_64
Then, in a second step, you can decide if you want to remove them one by one.
It is indeed not advisable to automate this procedure if you don’t want to take any risk!
Leave a Reply
You must be logged in to post a comment.