Chapter 4. Using RPM to Upgrade Packages

Table 4-1. rpm -U Command Syntax

rpm -U (or --upgrade)options file1.rpmfileN.rpm
Parameters
file1.rpmfileN.rpm One or more RPM package files (URLs OK)
Upgrade-specific Options Page
-h (or --hash) Print hash marks ("#") during upgrade[a] Section 2.3.2
--oldpackage Permit "upgrading" to an older package Section 4.3.1
--test Perform upgrade tests only[a] Section 2.4.2
--excludedocs Do not install documentation[a] Section 2.4.7
--includedocs Install documentation[a] Section 2.4.8
--replacepkgs Replace a package with a new copy of itself[a] Section 2.4.3
--replacefiles Replace files owned by another package[a] Section 2.4.4
--force Ignore package and file conflicts Section 4.3.2
--percent Print percentages during upgrade[a] Section 2.4.11
--noscripts Do not execute pre- and post-install scripts Section 4.3.3
--prefix <path> Relocate package to <path> if possible[a] Section 2.4.9
--ignorearch Do not verify package architecture[a] Section 2.4.17
--ignoreos Do not verify package operating system[a] Section 2.4.18
--nodeps Do not check dependencies[a] Section 2.4.5
--ftpproxy <host> Use <host> as the FTP proxy[a] Section 2.4.16
--ftpport <port> Use <port> as the FTP port[a] Section 2.4.15
General Options Page
-v Display additional information[a] Section 2.3.1
-vv Display debugging information[a] Section 2.4.1
--root <path> Set alternate root to <path>[a] Section 2.4.13
--rcfile <rcfile> Set alternate rpmrc file to <rcfile>[a] Section 2.4.12
--dbpath <path> Use <path> to find the RPM database [a] Section 2.4.14
Notes:
a. This option behaves identically to the same option used with rpm -i. Please see Chapter 2 for more information on this option.

4.1. rpm -U — What Does it Do?

If there was one RPM command that could win over friends, it would be RPM's upgrade command. After all, anyone who has ever tried to install a newer version of any software knows what a traumatic experience it can be. With RPM, though, this process is reduced to a single command: rpm -U. The rpm -U command (--upgrade is equivalent) performs two distinct operations:

  1. Installs the desired package.

  2. Erases all older versions of the package, if any exist.

If it sounds to you like rpm -U is nothing more than an rpm -i command (see Chapter 2) followed by the appropriate number of rpm -e commands, (see Chapter 3) you'd be exactly right. In fact, we'll be referring back to those chapters as we discuss rpm -U, so if you haven't skimmed those chapters yet, you might want to do that now.

While some people might think it's a "cheap shot" to claim that RPM performs an upgrade when in fact it's just doing the equivalent of a couple of other commands, in fact, it's a very smart thing to do. By carefully crafting RPM's package installation and erasure commands to do the work required during an upgrade, it makes RPM more tolerant of misuse by preserving important files even if an upgrade isn't being done.

If RPM had been written with a very "smart" upgrade command, and the install and erase commands couldn't handle upgrade situations at all, installing a package could overwrite a modified configuration file. Likewise, erasing a package would also mean that config files could be erased. Not a good situation! However, RPM's approach to upgrades makes it possible to handle even the most tricky situation — having multiple versions of a package install simultaneously.

4.1.1. Config file magic

While the rpm -i and rpm -e commands each do their part to keep config files straight, it is with rpm -U that the full power of RPM's config file handling shows through. There are no less than six different scenarios that RPM takes into account when handling config files.

In order to make the appropriate decisions, RPM needs information. The information used to decide how to handle config files is a set of three large numbers known as MD5 checksums. An MD5 checksum is produced when a file is used as the input to a complex series of mathematical operations. The resulting checksum has a unique property, in that any change to the file's contents will result in a change to the checksum of that file. [1] Therefore, MD5 checksums are a powerful tool for quickly determining whether two different files have the same contents or not.

In the previous paragraph, we stated that RPM uses three different MD5 checksums to determine what should be done with a config file. The three checksums are:

  1. The MD5 checksum of the file when it was originally installed. We'll call this the original file.

  2. The MD5 checksum of the file as it exists at upgrade time. We'll call this the current file.

  3. The MD5 checksum of the corresponding file in the new package. We'll call this the new file.

Let's take a look at the various combinations of checksums, see what RPM will do because of them, and discuss why. In the following examples, we'll use the letters X, Y, and Z in place of lengthy MD5 checksums.

4.1.1.1. Original file = X, Current file = X, New file = X

In this case, the file originally installed was never modified. [2] The file in the new version of the package is identical to the file on disk.

In this case, RPM installs the new file, overwriting the original. You may be wondering why go to the trouble of installing the new file if it's just the same as the existing one. The reason is that aspects of the file other than its name and contents might have changed. The file's ownership, for example, might be different in the new version.

Notes

[1]

Actually, there's a one in 2128 chance a change will go undetected, but for all practical purposes, it's as close to perfect as we can get.

[2]

Or, as some sticklers for detail may note, it may have been modified, and subsequently those modifications were undone.