yum, rpm and duplicate versions

Apparently, when doing "yum update", and it fails miserably, you can end up with duplicate versions of packages in the RPM database. This seems harmless, but is annoying. yum provides a tool to check for this, but I was not able to find anything that would automatically repair it. So here's a little tip:

$ yum check duplicates | awk '/is a duplicate/ {print $6}' > /tmp/DUPES
$ yum remove `cat /tmp/DUPES`

 Of course, before you remove the dupes, make sure to examine the tmp file (/tmp/DUPES) and make sure it looks ok.

Update:

There seems to be a command to do this, package-cleanup has an option for it. E.g.

$ package-cleanup --cleandupes

However, testing this command on a second box having the same problem gave bad results, it seems to have uninstalled the "real" packages too.

Hacking: 

Comments

Re: yum, rpm and duplicate versions

Thanks this got me going in the right direction. Some other info on this is that you might be able to solve it first by running yum-complete-transaction which will finish or fix transaction state of yum if there are any looming failed transactions. In my case, I found that my problem is that I do updates on all my linux systems through ssh so when openssh is updated this causes the connection to be dropped and so the transaction fails leaving the duplicates. Also you can use package-cleanup --dupes to show the duplicates without doing anything yet.