How to Cleanup Package in Linux CentOS

Posted on

There is a tool according to several references for cleaning up packages in Linux CentOS. In the case of cleaning an old version, a duplicate package or multi version of the package, try this tool. That tool name is ‘package-cleanup’.

Before the tool is available in the operating system for further execution, first of all install the necessary package.

The following is the command for installing the package so that the tool ‘package-cleanup’ available in the command line :

[root@localhost lib64]# yum -y install yum-utils
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: xxxxxx.xxxx.xxx.xx
 * epel: xxxxxxx.xxxx.xxxx
 * extras: xxxxx.xxxx.xx.xx
 * ius: xxx.xxxxxx.xx
 * updates: xxxxxx.xxxx.xx.xx
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-45.el7 will be installed
--> Processing Dependency: python-kitchen for package: yum-utils-1.1.31-45.el7.noarch
--> Processing Dependency: libxml2-python for package: yum-utils-1.1.31-45.el7.noarch
--> Running transaction check
---> Package libxml2-python.x86_64 0:2.9.1-6.el7_2.3 will be installed
---> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed
--> Processing Dependency: python-chardet for package: python-kitchen-1.1.1-5.el7.noarch
--> Running transaction check
---> Package python-chardet.noarch 0:2.2.1-1.el7_1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================
 Package                                              Arch                                         Version                                                 Repository                                  Size
============================================================================================================================================================================================================
Installing:
 yum-utils                                            noarch                                       1.1.31-45.el7                                           base                                       119 k
Installing for dependencies:
 libxml2-python                                       x86_64                                       2.9.1-6.el7_2.3                                         base                                       247 k
 python-chardet                                       noarch                                       2.2.1-1.el7_1                                           base                                       227 k
 python-kitchen                                       noarch                                       1.1.1-5.el7                                             base                                       267 k

Transaction Summary
============================================================================================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 859 k
Installed size: 4.3 M
Downloading packages:
(1/4): libxml2-python-2.9.1-6.el7_2.3.x86_64.rpm                                                                                                                                     | 247 kB  00:00:00     
(2/4): python-kitchen-1.1.1-5.el7.noarch.rpm                                                                                                                                         | 267 kB  00:00:00     
(3/4): yum-utils-1.1.31-45.el7.noarch.rpm                                                                                                                                            | 119 kB  00:00:00     
(4/4): python-chardet-2.2.1-1.el7_1.noarch.rpm                                                                                                                                       | 227 kB  00:00:00     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                       340 kB/s | 859 kB  00:00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python-chardet-2.2.1-1.el7_1.noarch                                                                                                                                                      1/4 
  Installing : python-kitchen-1.1.1-5.el7.noarch                                                                                                                                                        2/4 
  Installing : libxml2-python-2.9.1-6.el7_2.3.x86_64                                                                                                                                                    3/4 
  Installing : yum-utils-1.1.31-45.el7.noarch                                                                                                                                                           4/4 
  Verifying  : yum-utils-1.1.31-45.el7.noarch                                                                                                                                                           1/4 
  Verifying  : libxml2-python-2.9.1-6.el7_2.3.x86_64                                                                                                                                                    2/4 
  Verifying  : python-kitchen-1.1.1-5.el7.noarch                                                                                                                                                        3/4 
  Verifying  : python-chardet-2.2.1-1.el7_1.noarch                                                                                                                                                      4/4 

Installed:
  yum-utils.noarch 0:1.1.31-45.el7                                                                                                                                                                          

Dependency Installed:
  libxml2-python.x86_64 0:2.9.1-6.el7_2.3                              python-chardet.noarch 0:2.2.1-1.el7_1                              python-kitchen.noarch 0:1.1.1-5.el7                             

Complete!
[root@localhost lib64]#

There are several variety of command for cleaning up packages using ‘package-cleanup’.

1. Removing old kernel packages. Do it by typing the following command :

[root@localhost lib64]# package-cleanup --oldkernels
Loaded plugins: fastestmirror
No old kernels to remove
[root@localhost lib64]#

The output differs depend on the condition of the existing operating system. The above output is the case where there are no old kernels for removal.

2. Removing unused packages. Do it by typing the following command :

package-cleanup --leaves

For an example to list unused package :

[root@localhost lib64]# package-cleanup --leaves
Loaded plugins: fastestmirror
libsysfs-2.1.0-16.el7.x86_64
libzip-0.10.1-8.el7.x86_64
[root@localhost lib64]#

Combine it with the ‘yum’ command to remove package, so the overall command for removing unused packages is in the following command execution :

[root@localhost lib64]# yum remove `package-cleanup --leaves`
Loaded plugins: fastestmirror
No Match for argument: Loaded
No Match for argument: plugins:
No Match for argument: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package libsysfs.x86_64 0:2.1.0-16.el7 will be erased
---> Package libzip.x86_64 0:0.10.1-8.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================
Package                                         Arch                                          Version                                               Repository                                        Size
============================================================================================================================================================================================================
Removing:
libsysfs                                        x86_64                                        2.1.0-16.el7                                          @anaconda                                        146 k
libzip                                          x86_64                                        0.10.1-8.el7                                          @base                                            104 k

Transaction Summary
============================================================================================================================================================================================================
Remove  2 Packages

Installed size: 250 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing    : libsysfs-2.1.0-16.el7.x86_64                                                                                                                                                             1/2
/sbin/ldconfig: /lib64/libfreebl3.so is not a symbolic link

Erasing    : libzip-0.10.1-8.el7.x86_64                                                                                                                                                               2/2
/sbin/ldconfig: /lib64/libfreebl3.so is not a symbolic link

Verifying  : libzip-0.10.1-8.el7.x86_64                                                                                                                                                               1/2
Verifying  : libsysfs-2.1.0-16.el7.x86_64                                                                                                                                                             2/2

Removed:
libsysfs.x86_64 0:2.1.0-16.el7                                                                        libzip.x86_64 0:0.10.1-8.el7

Complete!
[root@localhost lib64]#

Leave a Reply