Package Management with RPM

The Red Hat Package Manager (RPM) is an open packaging system, available for anyone to use, which runs on Red Hat Linux as well as other Linux and UNIX systems.

RPM packages typically have file names like

   foo-1.0-1.i386.rpm

The file name includes the package name (foo), version (1.0), release (1), and architecture (i386).

Installing
The -i is the install switch. I like to use the v for verbose messages in case if the installation fails. The h option shows our progress with hash marks.

   # rpm -ivh foo-1.0-1.i386.rpm
     foo                       ####################################

Package Already Installed

If the package of the same version is already installed, you will see:

   # rpm -ivh foo-1.0-1.i386.rpm
     foo                     package foo-1.0-1 is already installed

If you want to install the package anyway and the same version you are trying to install is already installed, you can use the –replacepkgs option, which tells RPM to ignore the error:

   # rpm -ivh --replacepkgs foo-1.0-1.i386.rpm
     foo                       ####################################

This option is helpful if files installed from the RPM were deleted or if you want the original configuration files from the RPM to be installed.

Conflicting Files

If you attempt to install a package that contains a file which has already been installed by another package or an earlier version of the same package, you’ll see:

   # rpm -ivh foo-1.0-1.i386.rpm
     foo           /usr/bin/foo conflicts with file from bar-1.0-1#

To make RPM ignore this error, use the –replacefiles option:

   # rpm -ivh --replacefiles foo-1.0-1.i386.rpm
     foo                       #####################################

Unresolved Dependency

RPM packages can “depend” on other packages, which means that they require other packages to be installed in order to run properly. If you try to install a package which has an unresolved dependency, you’ll see:

   # rpm -ivh foo-1.0-1.i386.rpm
     failed dependencies:
     bar is needed by foo-1.0-1

To handle this error you should install the requested packages. If you want to force the installation anyway (a bad idea since the package probably will not run correctly), use the –nodeps option.

   # rpm -ivh --nodeps foo-1.0-1.i386.rpm
     foo                       ####################################

Uninstalling or Removing

   # rpm -e foo

Notice that we used the package name foo, not the name of the original package file foo-1.0-1.i386.rpm.

You can encounter a dependency error when uninstalling a package if another installed package depends on the one you are trying to remove. For example:

   # rpm -e foo
     removing these packages would break dependencies:
     foo is needed by bar-1.0-1

To cause RPM to ignore this error and uninstall the package anyway (which is also a bad idea since the package that depends on it will probably fail to work properly), use the –nodeps option.

   # rpm -e --nodeps foo

Upgrade

A variation on an install is an upgrade. An upgrade is used when you want to put a more recent package in place of something that is currently installed (aka upgrade). The upgrade syntax is exactly the same as an install, but you replace the -i with a -U. (Notice it is a capital U).

   # rpm -Uvh –-nodeps foo-1.0-1.i386.rpm
     foo                       ####################################

Upgrading is really a combination of uninstalling and installing, so during an RPM upgrade you can encounter uninstalling and installing errors, plus one more. If RPM thinks you are trying to upgrade to a package with an older version number, you will see:

   # rpm -Uvh foo-1.0-1.i386.rpm
     foo    package foo-2.0-1 (which is newer) is already installed#

To cause RPM to “upgrade” anyway, use the –oldpackage option:

   # rpm -Uvh --oldpackage foo-1.0-1.i386.rpm
     foo                       ####################################

Freshening

Freshening a package is similar to upgrading one. Type the following command at a shell prompt:

   # rpm -Fvh foo-1.2-1.i386.rpm
     foo                       ####################################

Querying

Use the rpm -q command to query the database of installed packages. The rpm -q foo command will print the package name, version, and release number of the installed package foo:

   # rpm -q foo
     foo-2.0-1

Instead of specifying the package name, you can use the following options with -q to specify the package(s) you want to query. These are called Package Specification Options.

  • -a queries all currently installed packages.
  • -f will query the package which owns . When specifying a file, you must specify the full path of the file (for example, /usr/bin/ls).
  • -p queries the package .

   # rpm -qa
   # rpm –qf /usr/bin/uptime
   # rpm -qlp doom-1.8-9.i386.rpm

There are a number of ways to specify what information to display about queried packages. The following options are used to select the type of information for which you are searching. These are called Information Selection Options.

  • -i displays package information including name, description, release, size, build date, install date, vendor, and other miscellaneous information.
  • -l displays the list of files that the package contains.
  • -s displays the state of all the files in the package.
  • -d displays a list of files marked as documentation (man pages, info pages, READMEs, etc.).
  • -c displays a list of files marked as configuration files. These are the files you change after installation to adapt the package to your system (for example, sendmail.cf, passwd, inittab, etc.).

For the options that display lists of files, you can add -v to the command to display the lists in a familiar ls -l format.
Common Errors

Sometimes a package is not removed cleanly. Here is the situation, you try to install something and rpm says its already installed. You then try to remove it, and rpm says that is not installed. What can you do?

   # rpm -ivh --force package-1.0-5.i386.rpm

The –force option is your solution.

Dependencies are generally regarded as a good thing. Rpm has the capability to know if software has such prerequisites. In the real world, not everything on your system can always be from an rpm. If I install the new libxxx without rpm, then I install a rpm which depends on libxxx, it might cause an error and stop. I can use the –nodeps to tell rpm that I don’t need it to look out for me.

   # rpm -ivh –nodeps package-1.0-5.i386.rpm

Rebuilding an RPM from a Source RPM

To install a source RPM to create a binary RPM using the –rebuild option.

   # rpmbuild --rebuild package-1.0-5.i386.src.rpm

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s