How to install and manage packages in Linux with RPM

RPM or Red Hat Package Manager is the default package management solution for Linux distributions based on Red Hat Linux. It’s a pretty useful way to easily install, upgrade, and un-install packages on Linux machines. I remember the days when every Linux package had to be compiled. Let’s see how to perform some basic tasks with RPM.

List All Packages

Before installing a new package or upgrading and old one you sometimes want to check to make sure that it isn’t already installed. Here’s how you can get a list of all installed RPM packages:

# rpm -qa

gawk-3.1.3-10.1
pax-3.0-9
krbafs-1.2.2-6
esound-0.2.35-2
perl-XML-Encoding-1.01-26
perl-Digest-SHA1-2.07-5

Now a list of this kind can be pretty confusing. What I like to do is use this command along with grep. I filter the search with the package I’m looking for. So, if I’m trying to check if a certain PHP package is installed I would run the following search:

# rpm -qa | grep php

php-pdo-5.2.0-1.rhel4.ct
php-mbstring-5.2.0-1.rhel4.ct
php-mysql-5.2.0-1.rhel4.ct
php-imap-5.2.0-5
php-5.2.0-1.rhel4.ct
php-cli-5.2.0-1.rhel4.ct
php-gd-5.2.0-1.rhel4.ct

I can see what’s already installed and then decide if I need to install, upgrade, or remove anything.

Install and Upgrade Packages

There are a couple of websites I use to get my RPM packages – rpm.pbone.net and RPM Find. After downloading the .rpm file here’s how you can install a package:

# rpm -ivh package-name.rpm

To upgrade a package:

# rpm -Uvh package-name.rpm

You will quite often get an error from RPM saying it needs some other packages installed to install or upgrade the package you are trying to install. This is commonly referred to as “dependancy hell”. You just have to go back to the website from where you downloaded the package and look for the packages it depends on, and install them first.

Remove Packages

Removing packages with RPM is just as simple as installing or upgrading them. You need to make sure you get the complete name of the package you are trying to remove. Use the command to list the packages as shown above to get the full name of the package. Then run the following command:

# rpm -e package-name.rpm

Beware of getting into dependancy issues here as well.

1 thought on “How to install and manage packages in Linux with RPM”

  1. Pingback: Moblin: some useful rpm commands « Linux & Stuff

Leave a Comment

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