An Open Access Peon

23 February 2007

Removing Duplicate RPM Packages

To find a list of packages that have a newer version installed use:


rpm --last -qa | perl -n -e '/^(\S+)-\S+-\S+/; print "$&\n" if $SEEN{$1}; $SEEN{$1} ||= $_;' | sort | uniq >dupes.txt


The --last argument causes RPM to list packages by install date (newest first). We remove any packages with the same name as a more recently installed package.

To actually remove the packages (as root):


for i in $(cat dupes.txt); do rpm -e $i && echo $i; done


Depending on dependencies you may need to run this more than once.

6 Comments:

  • for i in $(cat dupes.txt); do rpm -e $1 && echo $1; done

    should be:

    for i in $(cat dupes.txt); do rpm -e $i && echo $i; done

    Thanks for the top part though!

    By Anonymous Jeff, at 5:06 pm  

  • after getting a list of duplicate rpms, I simply ran

    #yum remove xxx.i386

    on each rpm name (xxx). This helped me see what dependencies there were and check them against the duplicate list.

    also had to use .i686 suffix to remove a couple of rpms.

    rpm -qa does not return the arch type

    By Anonymous Anonymous, at 3:26 pm  

  • Thanks, this was very helpful.

    I ran into a couple RPMs that depended on each other, so had to remove them by hand.

    The error for that looks like:

    error: Failed dependencies:
    oddjob-libs = 0.27-7 is needed by (installed) oddjob-0.27-7.i386
    error: Failed dependencies:
    oddjob = 0.27-7 is needed by (installed) oddjob-libs-0.27-7.i386

    And the solution was to delete them both by hand at the same time:

    % rpm -e oddjob-0.27-7 oddjob-libs-0.27-7

    By Anonymous Anonymous, at 3:40 pm  

  • For uniq to work correctly you have to sort the input first!

    So your inital command line with rpm --last should end with | sort | uniq

    By Anonymous Anonymous, at 2:22 pm  

  • yum install yum-utils
    package-cleanup --cleandupes

    By Anonymous Anonymous, at 2:20 pm  

  • Amazing, simple and it works.

    >>>yum install yum-utils
    >>>package-cleanup --cleandupes

    By Anonymous Anonymous, at 6:51 pm  

Post a Comment

<< Home