RPM Common Usage Examples

The Red Hat Package Manager (RPM) has establised itself as one of the most popular distrubution formats for linux software today. A first time user may feel overwhelmed by a vast number of options available and this article will help a newhand to get familiar with RPM.

The traditional way to install a package was to retrival an archive and then extract its files into the system wide directories. This worked fine but system administrator may face lots of problems like how to update the packages without breaking former settings, how to uninstall the files smoothly and completely, and how to deal with the dependency issues, etc.

RPM is a useful tool for both managing your system and diagnosing and fixing these problems. The best way to learn this package management system is to look at some examples. It’s highly suggested to have a try with your own system.

  • Install and deinstall a package

For installation, “rpm -ivh package.rpm” is widely used, for details please check the output of “man rpm” or “rpm –help” for details. For deinstallation, “rpm -e package” works well. Keep note that the package’s name is changed here, the suffix is not needed.
Also you can install a file from the network, both http and ftp are supported. enter:

 rpm -ivh ftp://joseph@ftp.admon.org/rpm/sysstat-9.0.4-1.i586.rpm

You will be prompted for the password after which the file will be downloaded and installed.

  • Verify the entire system

Perhaps you have deleted some files by accident, but you are not sure what you deleted. To verify your entire system and see what might be missing, you could try the following command:  rpm -Va

If some files are missing or appear to have been corrupted, you should probably either re-install the package or uninstall and then re-install the package.

  • verify a file to find out which package owns it


rpm -qf /usr/bin/ssh

The output would look like the following:

  • Verify the package which owns the program

We can combine the above two examples, and verify the package that owns that program, but you do not know which package owns it. Enter the following command:

rpm -Vf /usr/bin/ssh

and now the appropriate package is verified. If nothing outputs, the package is good state.

  • Find out more information about a specified program

If you wanna find out more information about a specified program, try the following command to locate the documentation which came with the package:

rpm -qdf /usr/bin/ssh

The output would be similar to the following:

  • Listing Installed Packages

To list all the packages installed via RPM mechanisms, enter:

rpm -qa

This command prints out the installed package names stored in the RPM database, hence you either have to have the default database location specified in the $HOME/.rpmmacros file, or to append –dbpath $HOME/myrpmdb (or whatever is your private database location) to the directive.

  • Query information about a specified RPM

You may find a new RPM, but you do not know what it does. To find information about it, use the following command:

rpm -qpi sysstat-9.0.4-1.i586.rpm

The output would be similar to the following:

Name  : sysstat    Relocations: (not relocateable)
Version     : 9.0.4     Vendor: (none)
Release     : 1     Build Date: Sat Jul 18 21:51:44 2009
Install Date: (not installed)   Build Host: localhost
Group : Applications/System     Source RPM: sysstat-9.0.4-1.src.rpm
Size  : 665516   License: GPL
Signature   : (none)
Packager    : Damien Faure <damien-jn.faure@bull.net>
URL   : http://pagesperso-orange.fr/sebastien.godard/
Summary     : SAR, SADF, MPSTAT, IOSTAT and PIDSTAT for Linux
Description :
The sysstat package contains the sar, sadf, mpstat, iostat, pidstat
and sa tools for Linux.
The sar command collects and reports system activity information.
The information collected by sar can be saved in a file in a binary
format for future inspection. The statistics reported by sar concern
I/O transfer rates, paging activity, process-related activities,
interrupts, network activity, memory and swap space utilization, CPU
utilization, kernel activities and TTY statistics, among others. Both
UP and SMP machines are fully supported.
The sadf command may  be used to display data collected by sar in
various formats (CSV, XML, etc.).
The iostat command reports CPU utilization and I/O statistics for disks.
The mpstat command reports global and per-processor statistics.
The pidstat command reports statistics for Linux tasks (processes).
  • Perhaps you now want to see what files the specified RPM installs.

You would enter the following:

rpm -qpl sysstat-9.0.4-1.i586.rpm

The output is similar to the following:

  • Simple Unpacking of an RPM Archive

In many cases you would only need to extract files from an RPM archive, without performing complex operations with an RPM database. There is a simple way to do it:

rpm2cpio sysstat-9.0.4-1.i586.rpm | cpio -i -d -m

This method makes use of the generic GNU CPIO utility, which deals with copying files to and from archives. The rpm2cpio command converts from RPM to CPIO format, and the output of this conversion is redirected to the cpio command.

  • Creating a Private RPM Database

To achieve a higher flexibility and to get access to more RPM functionality, you may want to make a step forward and create your own RPM database. You only have to do it once, by issuing the following instructions:

mkdir $HOME/myrpmdb
rpmdb --initdb --dbpath $HOME/myrpmdb

or, for older versions of RPM:

mkdir $HOME/myrpmdb
rpm --initdb --dbpath $HOME/myrpmdb

Mentioned in this example directory $HOME/myrpmdb can of course be substituted with any other location which suits you best. The only requirement is that you must have write permissions in this location.

Having such a personal RPM database allows you to perform more complex operations with RPM packages, without resorting to simple unpacking and manual installation. To simplify your life even further, do the following:

echo '%_dbpath /home/joseph/myrpmdb' | cat >> $HOME/.rpmmacros

This will create a file .rpmmacros in your $HOME directory, and add there the line specifying the database location. In this example, /home/yourname/myrpmdb should be substituted with your RPM database path. This will instruct RPM to use always your personal database.

It may be useful to copy the system-wide database into your own one. RPM does not provide any tool for database synchronization, and you have to do it in a very normal way:

cp -prf /var/lib/rpm/* $HOME/myrpmdb/
  • Relocating RPM Packages

An RPM package may contain information on relocatable directories. Such directories are listed as Relocations, meaning that their contents can be relocated during the installation in another directory. To perform such an installation, do the following:

rpm -ivh package.rpm --relocate /oldlocation=/newlocation

Here /oldlocation is one of the relocatable directories of the package, and /newlocation is your preferred destination, specified as an absolute path starting with “/”.

As of RPM version 4.0.4, multiple relocations are possible. To use this option, specify several relocation pairs on the command line like this “–relocate /old=/new –relocate /old/subdir=/new/subdir

Order of such pairs in the line is important, as RPM will attempt to create new directories and can not skip a level. If the package information contains several relocations, you must specify a –relocate pair for all of them. As in the case of installation, you either have to have the default database location specified in the $HOME/.rpmmacros file, or to append “–dbpath $HOME/myrpmdb” to the directive.

These are just a few examples. As you use RPM, you may find more uses for it.

Share Button

6 thoughts on “RPM Common Usage Examples

  1. Cheers for the fantastic page – I enjoyed reading it! I always love reading this blog. 🙂

Leave a comment

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