Remove duplicate packages when querying the rpm database

Today I had to solve a RPM problem on a Red Hat Enterprise Linux WS release 4 (Nahant Update 6) system (RHEL4) where there were duplicate packages when querying the rpm database. This had happened after an upgrade to update 6 using up2date from the command line.

It seemed like i386 and x64 packages had gotten installed on some packages and this caused some problems, like logon authentication and execution of some programs.

Trying to remove a duplicate rpm package

# rpm -e libtool-libs-1.5.6-4.El4.2

gave the error message

error: "libtool-libs-1.5.6-4.El4.2" specifies multiple packages

After searching the Red Hat knowledge base I located article Why do I see duplicate packages when querying the rpm database? where it says it is necessary to specify the architecture of the package to remove.

# rpm -qa --queryformat %{NAME}-%{VERSION}-%{ARCH}\\n

If you add %{RELEASE} you can also determine if the package is from other package vendors like RPMForge.

Since this was a x64 system, I wanted to remove the i386 version

# rpm -e libtool-libs-1.5.6-4.El4.2.i386

This had to be done with every duplicate package on the system.
Locate the i386 packages that interfered with the x64 packages can be done using the command

rpm -qa | sort | uniq -d

These packages have dependencies so you have to add these manually, really fun job to do.

Edit:
In RHEL5 you can use yum to remove packages in a easy way

yum remove <package>.i386
yum remove <package>.x86_64