Wednesday, May 16, 2012

Comparing RPM packages installed on two hosts, without using temporary files

When setting up a new Linux server, it's often interesting to compare the list of packages that are installed on the new server, with the list of packages installed on an existing server. You can use the following command line, which makes use of Bash supports for process substitution, to show the difference between packages installed on the local host and on the remote host.
 # ssh root@remotehost 'rpm -qa | sort' | diff -u <(rpm -qa | sort) -


If the above command gives no output, it means that the two hosts have identical packages installed.

If you want to disregard the package version differences in the comparison, then you will need to use something like this:

 # ssh root@remotehost 'rpm -qa --queryformat "%{NAME}\n" | sort' | diff -u <(rpm -qa --queryformat "%{NAME}\n" | sort) -

Update(2013-07-02):
Following Paul Waterman's comment, I did try out his rpmscomp Perl script, and I did find it useful. So I would recommend you also give it a try:

https://github.com/pdwaterman/rpmscomp

Also, to help in removing packages, I have found the rpmreader package useful:

https://fedorahosted.org/rpmreaper/

1 comment:

Paul Waterman said...

Another alternative is a tool that I recently uploaded to GitHub: https://github.com/pdwaterman/rpmscomp

The rpmscomp tool allows you to quickly and easily compare the RPMs installed on any number of systems -- it'll go out and grab the list of what's installed and list out what's installed on all systems side-by-side (or just the diffs if that's what you'd prefer).

Example:

rpmscomp --diffonly @host1 @host2 @host3 @host4 @host5

It also has various other capabilities, such as the ability to grab and store lists of installed packages for later comparison.