Create a clean list of installed packages on CentOS/RHEL

You’d like to create a “clean” list of installed packages on your Linux server. Perhaps you’d like to ensure that your base O/S image is consistent across several machines. Here’s an easy recipe to do that.

First, login to the machine you want to use as your “golden image”, and run the command:

rpm -aq | tail -n +3 | cut -d ' ' -f1 | sort > rpm.list

This will cut off the first 2 lines of output from the “rpm -aq” command, which are garbage lines that do not contain useful package information. The “cut” command eliminates white space, and only returns the first field, which contains the clean package title installed on the machine. The final “sort” command in the pipeline sorts the list, and the output is dumped into the file “rpm.list”.

Now, move the file “rpm.list” to another machine with a baseline installation of CentOS or RHEL, and run the following command:

yum -y install $(cat rpm.list)

Don’t worry if some of the packages in “rpm.list” are already installed on the target machine, they will just be ignored. When complete, your images on both machines should match (unless the target machine has some superfluous packages installed not installed on the source machine, but we’re assuming here you’re starting with a basic O/S image).

I’ve found this to be a MUCH EASIER way to create consistency across server images than trying to clone. It’s faster, less error prone, and more direct. Of course, if you’re using VM images, you can just clone that very easily, load and then tweak for hostname, networking, etc. But this works well for “real” server images and is the most streamlined approach I’ve found.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.