CentOS yum -- pre-existing rpmdb issues

Root Cause

Interruption in the up2date or yum update process caused the installation of multiple versions of the same package.

Resolution

  1. If the system is Red Hat Enterprise Linux 5 or later, the package-cleanup command can be used:

$ package-cleanup --dupes $ package-cleanup --cleandupes

The --dupes command will list the duplicate packages installed on the machine, while the --cleandupes switch will remove the older versions. package-cleanup command is provided by the yum-utils package.

  1. If package-cleanup does not help or the system is Red Hat Enterprise Linux 4, remove packages manually using rpm:

$ rpm -e --justdb <package-name>-<old-version>

The '--justdb' switch is used to ensure that the package removal does not remove its files from the file system, removing it only from the rpm database.

Some duplicates may not removed because they are required by installed packages. You can try --cleandupes with --removenewestdupes, or review them with --dupes and remove manually.


WARNING: Solving problems like these will always be both dangerous and tedious. Please understand that some of the packages in your system are critical to the function of the system. Making changes involving such packages can be more difficult. Make sure you understand whatever you are thinking of doing, watch out for details, ask around for help, make backups/snapshots before trying anything as it's easy to make things worse instead of better. For some changes it may be necessary to boot a rescue disk so that you don't have to rely on the system you are trying to fix.

--

In my case I found that something had gone wrong and many packages had been updated without the older versions being removed. Attempts to rebuild the RPM DB did not solve the problem.

One solution that is working is simply to remove the older version and reinstall the newer version.

Looking at the error output each line basically says Update Package is a duplicate with Previous Package, ie:

    kernel-headers-2.6.32-431.17.1.el6.x86_64 is a duplicate with kernel-headers-2.6.32-358.23.2.el6.x86_64

The following seems to work for me:

    rpm --erase --nodeps --noscript kernel-headers-2.6.32-358.23.2.el6.x86_64

The command tells RPM to remove the specific Previous Package without removing any dependencies or running any scripts associated with the task.

Next the package needs to be reinstalled:

    yum reinstall kernel-headers

This time there's no need to specify the exact package version as yum will look for the most recent version and reinstall it.

Yum will output the result of its Yum Check operation during each run. Keep doing this until there are no more duplicate packages listed.

Note that you can query the RPM database directly. If you see lots of messages that include the string glibc, for example, you can get a simple list of packages which have that string in their names like this:

    rpm -qa | grep glibc | sort

Which might produce something like:

    glibc-2.17-157.el7_3.5.x86_64
    glibc-common-2.17-157.el7_3.4.x86_64
    glibc-common-2.17-157.el7_3.5.x86_64
    glibc-devel-2.17-157.el7_3.5.x86_64
    glibc-headers-2.17-157.el7_3.5.x86_64

Now it's more obvious that the previous version of glibc-common must be removed:

    rpm --erase --nodeps --noscript glibc-common-2.17-157.el7_3.4.x86_64
    yum reinstall glibc-common