==>OS
• Red Hat Enterprise Linux 8
• Red Hat Enterprise Linux 7
• Red Hat Enterprise Linux 6
• Red Hat Enterprise Linux 5
==>
Issue
• How to remove the older versions of a package which has multiple versions installed on
Red Hat Enterprise Linux?
• After a failed yum transaction, yum-complete-transaction fails to complete and the
duplicates are still present.
• yum fails with <package_name-version1> is a duplicate with <package_nameversion2>
• package-cleanup --cleandupes fails with Error: Depsolving loop limit reached
Resolution
1. Try to complete the transaction
2. Manually remove duplicates
3. Identify remaining rpm corruption
RHEL 5,6,7
• Before manually removing the duplicates, confirm if yum-complete-transaction will
resolve the issue.
• If this completes successfully, so long as there are no further duplicates, you do not
need to run the remaining steps.
• If there are no duplicates, we can clear this message with the --cleanup-only option
RHEL 8
• yum history redo can reattempt the transaction. We can use last or the transactionid
as the target
• With RHEL 8 comes the ability to remove the lower version and reinstall the higher
version, the same as the manual steps do.
• If this completes successfully, so long as there are no further duplicates, problems, or
concerns, you do not need to run the remaining steps.
Manually remove duplicates
The first step is to backup the rpm database. The remaining steps create a list of one oft he
duplicate package and removes them from the database only. With the --justdb flag we
ensure no necessary files are removed until after we update. If there is any concern that the
files are incorrect we can verify with rpm -Va .
RHEL 5
• RHEL 5 does not have yum check so we must use an alternate method.
RHEL 6,7
• yum check can take quite a while but the output is necessary for these steps
# tar cjf /tmp/rpm_db.tar.bz2 /var/lib/{rpm,yum}
# yum check &> /tmp/yumcheck
#grep "duplicate" /tmp/yumcheck | awk '{ print $NF }' | egrep -v "\:" >
/tmp/duplicaterpms
# grep "duplicate" /tmp/yumcheck | awk '{ print $NF }' | egrep
":" | awk -F':' '{ print $NF }' >> /tmp/duplicaterpms
# for i in $(cat
/tmp/duplicaterpms); do rpm -e --justdb --nodeps $i; done # yum update
RHEL 8
• For RHEL 8, we want to backup /var/lib/dnf and /etc/dnf*
# tar cjf /tmp/rpm_db.tar.bz2 /var/lib/{rpm,dnf} /etc/{dnf*,os-release} /usr/lib
/os-release # repoquery --duplicated --latest-limit=-1 -q &> /tmp/duplicateolder #
for i in `cat /tmp/duplicateolder`; do rpm -ev --justdb --nodeps $i; done # yum
update
After removing the Duplicates
• If a new kernel was part of the transaction that failed, you may have to reinstall that
kernel as well to generate the correct grub entries and initrd/initramfs
# yum remove kernel-*<version>-<release>.<arch> # yum install kernel-<version>-
<release>.<arch>
Identify remaining rpm corruption
• To identify any remaining corruption we can use rpm -Va which verifies all files on the
system that are provided by rpms, against the rpms you have installed.
◦ If there are duplicates on the system, an rpm -Va will be extremely misleading
suggesting that most of the binaries are wrong when in fact it's comparing 1 binary
against 2 packages and telling you that it doesn't match one of the 2 it checked. By
removing the duplicates first, we can then use rpm -Va to identify any remaining
rpm vs file mismatch.
• If you have prelinking enabled, we want to clear that cache first before running rpm -Va
or it obscures the output.