Book: LPI Linux Certification in a Nutshell Section: Chapter 14. Linux Installation and Package Management (Topic 2.2)
### 14.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 many distributions. It automatically handles many of the management details associated with interdependent software running on your system. #### 14.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 it's consulted on a file-by-file basis for dependencies when packages are removed, queried, and installed. As with Debian packages, RPM filenames have three common elements: Name 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. Version Each package has a version. Most package versions are the same as that of the software they contain, thus the format of package versions varies from package to package. Most are numeric, with major, patch, and release numbers, but other information may appear as well. Typical versions are 3.0beta5-7, 1.05a-4, 2.7-5, 1.10.5-2, 1.1.1pre2-2, 1.14r4-4, 6.5.2-free3-rsaref, and 0.9_alpha3-6. The version is separated from the name by a hyphen. Architecture 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. For Sun and Sun-compatible processors, the architecture is sparc. The architecture is separated from the version with a dot. A .rpm extension All RPM files end with .rpm extension by default. An RPM filename is constructed by tying these elements together in one long string, as shown in Figure 14-2. ##### Figure 14-2. The structure of an RPM package name As you can see, there are three uses for hyphens in RPM filenames. They appear as word separators in package names, as a delimiter between names and versions, and as part of the version. This may be confusing at first, but the version is usually obvious, making the use of hyphens unambiguous.[9] [9] Perhaps this won't be clear at first glance, but once you're used to RPM names you'll know what to expect. #### 14.6.2 Running rpm The rpm command provides for the installation, removal, upgrade, verification, and other management of RPM packages and has a bewildering array of options. Some are of the traditional single-letter style, while others are the -- option variety. In most cases, both styles exist and are interchangeable. At first glance, configuring rpm may appear to be a bit daunting. However, its operation is segmented into modes, which 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 |
#### Syntax
    rpm -i (also rpm  --  install),
    rpm -U (also rpm  -- upgrade)
    rpm -e (also  -- uninstall)
    rpm -q (also  -- query)
    rpm -V
#### 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. #### Frequently used install- and upgrade-mode options -- force This option 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. -h (also -- hash) This option adds a string of 50 hash marks (`#`) during installation as a sort of progress indicator. -- nodeps rpm will skip dependency checking with this option enabled. This allows you to install a package without regard to dependencies. -- test This option will run 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. -v This option sets verbose mode. -vv This 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 -iv netscape-communicator-4.72-3.i386.rpm
    error: failed dependencies:
            netscape-common = 4.72 is needed by
            netscape-communicator-4.72-3
To correct the problem, the dependency must first be satisfied. In this example, netscape-communicator is dependent on netscape-common, which is installed first:
    # rpm -iv netscape-common-4.72-3.i386.rpm
    netscape-common
    # rpm -iv netscape-communicator-4.72-3.i386.rpm
    netscape-communicator
#### 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 netscape-common-4.72-3.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-mode options -- nodeps rpm skips dependency checking with this option enabled. -- test 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. #### Example Package removal is the opposite of installation and has the same dependency constraints:
    # rpm -e netscape-common
    error: removing these packages would break dependencies:
            netscape-common = 4.72 is needed by
            netscape-communicator-4.72-3
#### 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-mode 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-mode 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 xv-3.10a-13.i386.rpm | grep Version
    Version     : 3.10a                Vendor: Red Hat Software
For installed packages, omit the -p option and specify a package name instead of a package filename:
    # rpm -qi kernel-source | grep Version
    Version     : 2.2.5                Vendor: Red Hat Software
#### Example 2 Enter query mode and list the files contained in a package:
    # rpm -qlp gnucash-1.3.0-1.i386.rpm
    /usr/bin/gnc-prices
    /usr/bin/gnucash
    /usr/bin/gnucash.gnome
    /usr/doc/gnucash
    /usr/doc/gnucash/CHANGES
      (...output continues ...)
For an installed package, enter query mode and use the -l option along with the package name:
    # rpm -ql kernel-source
    /usr/src/linux-2.2.5/COPYING
    /usr/src/linux-2.2.5/CREDITS
    /usr/src/linux-2.2.5/Documentation
    /usr/src/linux-2.2.5/Documentation/00-INDEX
    /usr/src/linux-2.2.5/Documentation/ARM-README
      (...output continues ...)
#### Example 3 List the documentation files in a package:
    # rpm -qd at
    /usr/doc/at-3.1.7/ChangeLog
    /usr/doc/at-3.1.7/Copyright
    /usr/doc/at-3.1.7/Problems
    /usr/doc/at-3.1.7/README
    /usr/doc/at-3.1.7/timespec
    /usr/man/man1/at.1
    /usr/man/man1/atq.1
    /usr/man/man1/atrm.1
    /usr/man/man1/batch.1
    /usr/man/man8/atd.8
    /usr/man/man8/atrun.8
Use -p for package filenames. #### Example 4 List configuration files or scripts in a package:
    # rpm -qc at
    /etc/at.deny
    /etc/rc.d/init.d/atd
#### Example 5 Determine the package from which a particular file was installed. Of course, not all files originate from packages:
    # rpm -qf /etc/issue
    file /etc/issue is not owned by any package
Those that are package members look like this:
    # rpm -qf /etc/aliases
    sendmail-8.9.3-10
#### Example 6 List the packages that have been installed on the system (all or a subset):
    # 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
    kernel-headers-2.2.5-15
    kernel-2.2.5-15
    kernel-pcmcia-cs-2.2.5-15
    kernel-smp-2.2.5-15
    kernel-source-2.2.5-15
    kernelcfg-0.5-5
    kernel-ibcs-2.2.5-15
    kernel-doc-2.2.5-15
#### 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 in Section 21.1. #### Frequently used verify-mode options -- nofiles Ignores missing files. -- nomd5 Ignores MD5 checksum errors. -- nopgp Ignores PGP checking errors. #### Additional operational modes There are also modes in RPM for building, rebuilding, signing, and checking the signature of RPM files; however, these are beyond the scope of the LPIC Level 1 exams.
## 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.