Analyze and clean-up installed RPM packages with package-cleanup

During the installation of kernel updates I stumbled upon a cramped /boot partition recently. Solving this issue is quite easy - e.g. it is possible to manually dig through the RPM database, exclude the running kernel and remove all other packages. Anyhow, this is neither comfortable nor elegant:

1# yum remove `rpm -qa|grep kernel|grep -v $(uname -r)|tr "n" " "`

On RPM-based distributions that are using YUM or DNF, there is a might tool named package-cleanup for analyzing and cleaning the RPM database. The following command can be used to remove all kernels except the current one in a very comfortable way:

1# package-cleanup --oldkernels --count 1 -y
2--> Running transaction check
3---> Package kernel.x86_64 0:3.10.0-229.11.1.el7 will be erased
4---> Package kernel.x86_64 0:3.10.0-229.14.1.el7 will be erased
5---> Package kernel.x86_64 0:3.10.0-327.3.1.el7 will be erased
6--> Finished Dependency Resolution
7...

By customizing the --count parameter, older kernel versions can be kept as well - e.g. 2 for the most recent and previous one.

This behavior can be included in the YUM configuration to avoid this issue in the future:

1# vi /etc/yum.conf
2[main]
3...
4installonly_limit=1
5
6ESC ZZ

Die value needs to be replaced by the amount of package revisions that should be kept - e.g. 2 for the most recent and previous one.

The utility offers additional functions for analyzing and cleaning the RPM database - some examples:

Parameter Explanation
--problems List dependency problems
--orphans List packages that are installed but not part of any currently used software source
--dupes --cleandupes Detect  (--dupes) and clean (--cleandupes) duplicates.
--leaves Remove "leaf nodes"; packages, that are not referenced by other packages

The following example lists "leaf nodes":

1# package-cleanup --leaves
2glib2-devel-2.42.2-5.el7.armv7hl
3libidn-devel-1.28-4.el7.armv7hl
4libxml2-devel-2.9.1-6.el7.2.armv7hl

Before removing the packages you should double-check whether they are needed. In this case the utility reports development files that were used for compiling software. Therefor, the packages are not referenced by other packages - but maybe it is required to compile a newer version of the software? 😉

The next example lists installed packages, that are not part of any currently used software source:

1# package-cleanup --orphans
2m2crypto-0.21.1-15.el7.armv7hl

The last command lists dependency problems:

1# package-cleanup --problems
2Package libxml2-devel-2.9.1-6.el7.2.armv7hl has missing requires of xz-devel

In this case, a RPM package was installed outside YUM - creating an erroneous dependency.

Translations: