Previous Page
Next Page

4.6. Objective 6: Use Red Hat Package Manager (RPM)

The Red Hat Package Manager is among the most popular methods for the distribution of software for Linux and is installed by default on most distributions. It automatically handles many of the management details associated with interdependent software running on your system.

4.6.1. RPM Overview

RPM automates the installation and maintenance of software packages. Built into each package are program files, configuration files, documentation, and dependencies on other packages. Package files are manipulated using the rpm command, which maintains a database of all installed packages and their files. Information from new packages is added to this database, and the database is consulted on a file-by-file basis for dependencies when packages are removed, queried, and installed. As with Debian packages, RPM packages have four common elements:


An RPM package name is short and descriptive. If multiple words are used, they are separated by hyphens (not underscores, as you might expect). Typical names include binutils, caching-nameserver, cvs, gmc, kernel-source, and telnet.


Each package has a version. Most package versions are the same as that of the software they contain. The format of package versions varies from package to package, but most are numeric (major.minor.patchlevel).


The revision tag is simply a release number for the package. It has no significance except to determine if one package is newer than another when the version number does not change.


Packages containing binary (compiled) files are by their nature specific to a particular type of system. For PCs, the RPM architecture designation is i386, meaning the Intel 80386 and subsequent line of microprocessors and compatibles.

Packages optimized for later x86 CPUs will have an architecture tag appropriate for the specific CPU the code is compiled for, such as i586 for Intel Pentium (and compatible) processors, i686 for Intel Pentium Pro and later processors (Pentium II, Celeron, Pentium III, and Pentium 4), or athlon for AMD Athlon.

Other possible architecture tags include alpha, ia64, ppc, and sparc (for the Alpha, Itanium, PowerPC, and SPARC, respectively). Another arch tag, noarch, is used to indicate packages that can install on any architecture.

While the filename of an RPM package is not significant, Red Hat does have a standard naming scheme for its packages that most of the other RPM-based distributions also follow. It is constructed by tying these elements together in one long string.

4.6.2. Running rpm

The rpm command provides for the installation, removal, upgrade, verification, and other management of RPM packages. rpm has a bewildering array of options, including the traditional single-letter style (-i), and the double-dash full word style (--install). In most cases, both styles exist and are interchangeable.

Although configuring rpm may appear to be a bit daunting, its operation is simplified by being segmented into modes. rpm modes are enabled using one (and only one) of the mode options. Within a mode, additional mode-specific options become available to modify the behavior of rpm. The major modes of rpm and some of the most frequently used mode-specific options follow. For complete information on how to use and manage RPM packages, see the rpm manpage or the synopsis offered by rpm --help.


rpm -i  [options ]
(also rpm  --install)
rpm -U  [options ] (also rpm --upgrade)
rpm -e  [options ] (also rpm --uninstall)
rpm -q  [options ] (also rpm --query)
rpm -V  [options ] (also rpm --verify)

Install/upgrade mode

The install mode (rpm -i) is used to install new packages. A variant of install mode is the upgrade mode (rpm -U), where an installed package is upgraded to a more recent version. Another variant is the freshen mode (rpm -F), which only upgrades packages where an older version is already installed on the system. rpm's -F option has historically been of limited usefulness since it doesn't handle dependency changes at all. In other words, if a new version of a package requires that another package be installed, -F won't automatically install the new package, even if it is listed on the command line.

Frequently used install and upgrade options


Allows the replacement of existing packages and of files from previously installed packages; for upgrades, it allows the replacement of a newer package with an older one. (Literally, it is equivalent to setting all of the options --replacepkgs, --replacefiles, and --oldpackage. Use this option with caution.

-h (also --hash)

Prints a string of 50 hash marks (#) during installation as a progress indicator.


Allows you to install a package without checking for dependencies. This command should be avoided, since it makes the dependency database inconsistent.


Runs through all the motions except for actually writing files; it's useful to verify that a package will install correctly prior to making the attempt. Note that verbose and hash options cannot be used with --test, but -vv can.


Sets verbose mode. (Package names are displayed as the packages are being installed.)


Sets really verbose mode. The manpage describes this as "print lots of ugly debugging information."

Example 1

To install a new package, simply use the rpm -i command with the name of a package file. If the new package depends upon another package, the install fails, like this:

# rpm -i gcc-2.96-113.i386.rpm
error: failed dependencies:
        binutils >= is needed by gcc-2.96-113
        cpp = 2.96-113 is needed by gcc-2.96-113
        glibc-devel is needed by gcc-2.96-113

To correct the problem, the dependency must first be satisfied. In this example, gcc is dependent on binutils, cpp, and glibc-devel, which all must be installed first (or at the same time, as in this example):

# rpm -i binutils- cpp-2.96-113.i386.rpm \
  glibc-devel-2.2.5-44.i386.rpm gcc-2.96-113.i386.rpm

Example 2

Upgrading an existing package to a newer version can be done with the -U option. Upgrade mode is really a special case of the install mode, where existing packages can be superseded by newer versions. Using -U, a package can be installed even if it doesn't already exist, in which case it behaves just like -i:

# rpm -U gcc-2.96-113.i386.rpm

Uninstall mode

This mode is used to remove installed packages from the system. By default, rpm uninstalls a package only if no other packages are dependent on it.

Frequently used uninstall options


rpm skips dependency checking with this option enabled. This command should be avoided, since it makes the dependency database inconsistent.


This option runs through all the motions except for actually uninstalling things; it's useful to verify that a package can be uninstalled correctly without breaking other dependencies prior to making the attempt. Note that verbose and hash options cannot be used with --test, but -vv can.


Package removal is the opposite of installation and has the same dependency constraints:

# rpm -e glibc-devel
error: removing these packages would break dependencies:
        glibc-devel is needed by gcc-2.96-113

Query mode

Installed packages and raw package files can be queried using the rpm -q command. Query-mode options exist for package and information selection.

Frequently used query package selection options

-a (also --all)

Display a list of all packages installed on the system. This is particularly useful when piped to grep if you're not sure of the name of a package or when you want to look for packages that share a common attribute.

-f filename (also --file)

Display the package that contains a particular file.

-p package_filename

Query a package file. Most useful with -i, described next.

Frequently used query information selection options

-c (also --configfiles)

List only configuration files.

-d (also --docfiles)

List only documentation files.

-i package

Not to be confused with the install mode. Display information about an installed package, or when combined with -p, about a package file. In the latter case, package is a filename.

-l package (also --list)

List all of the files contained in package. When used with -p, the package is a filename.

-R (also --requires)

List packages on which this package depends.

Example 1

To determine the version of the software contained in an RPM file, use the query and package information options:

# rpm -qpi openssh-3.4p1-2.i386.rpm | grep Version
Version     : 3.4p1                Vendor: Red Hat, Inc.

For installed packages, omit the -p option and specify a package name instead of a package filename. Notice if you have multiple versions of the same package installed, you will get output for all of the packages:

# rpm -qi kernel-source | grep Version
Version     : 2.4.9                             Vendor: Red Hat, Inc.
Version     : 2.4.18                            Vendor: Red Hat, Inc.
Version     : 2.4.18                            Vendor: Red Hat, Inc.

Example 2

List the files contained in a package:

# rpm -qlp gnucash-1.3.0-1.i386.rpm 
 (...output continues ...)

For an installed package, enter query mode and use the -l option along with the package name:

# rpm -ql kernel-source 
  (...output continues ...)

Example 3

List the documentation files in a package:

# rpm -qd at

Use -p for package filenames.

Example 4

List configuration files or scripts in a package:

# rpm -qc at

Example 5

Determine what package a particular file was installed from. Of course, not all files originate from packages:

# rpm -qf /etc/fstab
file /etc/fstab is not owned by any package

Those that are package members look like this:

# rpm -qf /etc/aliases

Example 6

List the packages that have been installed on the system.

# rpm -qa 
 (... hundreds of packages are listed ...)

To search for a subset with kernel in the name, pipe the previous command to grep:

# rpm -qa | grep kernel

Verify mode

Files from installed packages can be compared against their expected configuration from the RPM database by using rpm -V. The output is described under Objective 1 in Chapter 21.

Frequently used verify options


Ignores missing files.


Ignores MD5 checksum errors.


Ignores PGP checking errors.

On the Exam

Make certain that you are aware of rpm's major operational modes and their commonly used mode-specific options. Knowledge of specific options will be necessary. Read through the rpm manpage at least once.

Previous Page
Next Page