RPM RedHat Package Manager

RPM RedHat Package Manager

Keith Winston

RPM is the Red Hat package manager. It is a program designed to build and manage packages of software including the source and binaries. It is portable and can be run on different platforms.

RPMs (*.rpm) typically include the compiled programs and/or libraries needed for the package, documentation, install, verify, and uninstall scripts, and cryptographic signatures for each file in the package. This makes it easy to verify the integrity of the package. It also includes a list of packages that it depends on, and a list of services that are provided by the package.

RPM maintains a database of all installed packages in /var/lib/rpm/*. Included in the database is a list of all files installed by RPM and which package they belong to. This makes it a very powerful tool for finding out more about each package.

Sources are often provided in source RPMs (*.src.rpm or *.spm). These sources include the pristine developer source code, any patches applied by the package builder, and a SPEC file that is used to tell rpm how to compile the package.

You have to logged in as user root to install, upgrade, or remove packages. You can run queries as any user.

The RPM package format has been adopted by many major distributions besides Red Hat, including SuSE, Caldera, and TurboLinux.

Install and Upgrade commands

To install a package (i=install v=verbose h=show hash marks)rpm -ivh package
To uninstall (erase) a packagerpm -e package
To upgrade a packagerpm -Uvh package
To test a package to see how it would install (without installing, also checks dependencies)rpm -Uvh --test package

Verify commands

To verify a package (extra verbose output)rpm -Vvv package
To verify ALL installed packages on the systemrpm -Va
To verify the cryptographic signature of a package rpm -K package

Query commands

These commands query a package that has already been installed. To query a package that has NOT been installed yet, add the -p option to the command.

For example, rpm -ql package would become rpm -qpl package.
To find out the package names using wildcardsrpm -qa | grep pattern
What files are included in the the package rpm -ql package
To show general info on a package rpm -qi package
What package owns this file? rpm -qf path/to/file
What are the config files in a package? rpm -qc package
What are the documentation files in a package? rpm -qd package
What are the scripts in a package? rpm -q --scripts package
What services does this package provide? rpm -q --provides package
What services does this package require? rpm -q --requires package

Using RPM to build/install from source

To build/install an rpm source package

  1. rpm -ivh source-package

    This installs the source in /usr/src/packages/SOURCES and installs the spec file in /usr/src/packages/SPECS.


    RedHat systems use /usr/src/redhat/SOURCES and /usr/src/redhat/SPECS. Make a note of this if you are trying to use a package prepared for RedHat

  2. rpm -ba spec-file OR rpm --rebuild spec-file

    This compiles the source and builds a binary rpm, then places it in /usr/src/packages/RPMS/Architecture.

    Building a package from an rpm source package starts with the pristine sources from the developer, applies any patches from the package builder, and uses options in the SPEC file to compile and create the binary package.

  3. rpm -ivh package

    This installs the binary package.

To extract the sources and apply patches from a source package (without building an rpm)

  1. rpm -ivh source-package

    This installs the source in /usr/src/packages/SOURCES and installs the spec file in /usr/src/packages/SPECS.

  2. rpm -bp spec-file

    This extracts the sources into /usr/src/packages/BUILD and applies any patches from the source package, but does not compile it or create a binary rpm package.

Bypass RPM scripts

To bypass running the scripts in a package, use the --no-scripts option. There are 5 possible scripts in an rpm package:

  • pre-install

  • post-install

  • verify

  • pre-uninstall

  • post-uninstall

If you suspect the RPM database has been corrupted, run rpm --rebuilddb to rebuild it and try to recover from any errors.

Extract individual files from an RPM

To extract an individual file from an rpm package without installing the rpm:

  1. Use rpm2cpio or rpm -qpl to list files and full paths in the package: rpm2cpio package | cpio -t

    You need the full path name of a file to extract it in step 2.

  2. Use rpm2cpio to extract a file. Run this command from your home directory or /tmp in order to avoid overwriting any current system files.

    	  rpm2cpio package | cpio -iv --make-directories full-path

    This creates the full path in the current directory and extracts the file you specified.

  3. If you just want to convert it to a cpio archive, use

    	  rpm2cpio package > cpio-archive-file

RPM mass uninstall

If you want to remove a list of RPMs without typing each on separately, you can use the xargs command with rpm. Here are the commands and output from a session where I wanted to delete several RPMs at once. First, I used rpm -qa to find all the xine RPMs. When I verified the list, I passed the list to xargs to execute an rpm -e on each of them. The final rpm -qa verifies that they have all been uninstalled.

artifact:~/datacore/suse-7.3/xine # rpm -qa | grep xine
artifact:~/datacore/suse-7.3/xine # rpm -qa | grep xine | xargs rpm -e
artifact:~/datacore/suse-7.3/xine # rpm -qa | grep xine
artifact:~/datacore/suse-7.3/xine #


Updated: Tue, 03 Feb 2004
Valid CSS!Valid HTML 4.01!