Fixing Duplicate Packages When Upgrading Process RedHat

This is the way I did fix one CentOS/RedHat 7 server with 471 dupes.
First I had to install yum utils:

yum install yum-utils

Have tried yum-complete-transaction and other stuff without luck, I gave up the transaction with:

yum-complete-transaction --cleanup-only

Then I got a sorted list of duplicated packages so I could identify older versions to remove filtering even and odd lines later:

package-cleanup --dupes | sort -u > dupes.out

Then I got a uninstall list from this sorted file this way:

cat dupes.out | grep -v 'Loaded plugins:' | sort -u | awk 'NR % 2 == 1' > uninstall.in

Then I removed from rpm database the old versions:

for f in `cat uninstall.in`; do rpm -e --nodeps -f --justdb $f; done

Finally I could continue on regular system upgrade:

yum upgrade

Some things to pay attention:

  • On this case, I have carefully reviewed the “package-cleanup –dupes” output to make sure how to generate the uninstall list.
  • I have tried a “reinstall the newer” approach inverting the list (awk ‘NR % 2 == 0’) but there where lots of packages not available anymore at that version (server was left this way for an year).
  • I thought about removing from rpmdb the newer packages, so upgrade later should reinstall everything, but after checking on filesystem installed files, it was clear for me that new versions were in place, with only older rpm entries still in rpmdb. Maybe your case is different.