tip: automated way to delete duplicate rpms

Kim Lux lux at diesel-research.com
Sat Dec 30 06:24:09 UTC 2006


I recently updated a server from fc3 to fc6.  All seemed to go well
except the first yum attempt to update the machine failed and when I
entered synaptic I received a ton of errors about duplicate rpms
installed on the machine.  I've run into this issue before.
Unfortunately neither yum nor synaptic has a way to deal with it, as far
as I can tell.   

Rather than manually go through the list of offending rpms and delete
them, I did things semi automatically.  There were 120 duplicate rpms on
my machine, so manually typing the full package names would have taken a
while.

Here is what I did instead.

1) Generate a list of all the rpm packages installed.

$rpm -qa --queryformat '%{name}\n' > pkglist

This generates an unsorted list that looks like this.
libavc1394
libmusicbrainz
ethtool
desktop-file-utils
less
time
libXrandr
rmt

2) Sort the list and find the duplicates

$sort -g pkglist | uniq -d > duplicates

This list will look like 

a2ps
anacron
at
audit
...

3) Generate a list of the packages with versions to look at and edit

I created a small script file called dupWithVersions with this in it

for pkg in `cat duplicates`; do
  rpm -q $pkg
done

Redirect the output to another file like this.  $dupWithVersions
>removeList

The remove list will look like this:

a2ps-4.13b-57
a2ps-4.13b-57.fc6.3
anacron-2.3-41.fc6
anacron-2.3-44.fc6
at-3.1.8-82.fc6
at-3.1.8-84.fc6
audit-1.2.8-1.fc6
audit-1.3-2.fc6

Go through the remove list and manually remove the versions you want to
KEEP !  Remember this is a list of rpms you want to remove !

4) Remove the rpms in the remove list.

To do this I generated a little script as follows:

for pkg in `cat removelist`; do
  rpm -e $pkg
done

This process quickly and correctly removed the duplicate rpms from my
machine. 

I hope this helps someone. 












 

-- 
Kim Lux,  Diesel Research Inc.





More information about the fedora-list mailing list