RPM

From LQWiki
Jump to navigation Jump to search

RPM stands for RPM Package Manager. Depending on the context, RPM can mean either the rpm program, which manages installed software, or the file format it uses - rpm files. The rpm file format is a container for distributing software as packages, either in pre-compiled binary or source code form.

RPM packages are usually targeted at a particular distribution and CPU architecture. By convention this information is reflected in the filename. For example, the file foo-1.2.3-2.rh9.i386.rpm contains version 1.2.3 of the program foo, compiled for Intel 386 computers with Red Hat 9 in mind. If the cpu is given as noarch the program is not platform dependent and should run on any architecture. RPM files containing source code end .src.rpm, although the distinction is not always clear with interpreted languages like Perl.

RPM maintains a local database, which keeps track of all installed software.

RPM was developed by Red Hat and used to stand for Red Hat Package Manager.

Installing RPM Packages

An RPM package can be installed either from an rpm file on the local filesystem, or from remote locations using apt or yum. Apt and yum download the file for you and pass it to the rpm program (see their pages for more instructions). Instructions here deal with using the rpm program directly.

The following examples assume that there is a file called 'nameOfPackage.rpm' in the current directory, and that you are at a root prompt.

To install an RPM package:

# rpm -ivh nameOfPackage.rpm

The command-line flags indicate (i)nstallation, (v)erbose reporting, and (h)ash marks printed to indicate progress. v and h are not necessary, but with them rpm outputs progress information during the install.

To upgrade a currently-installed package to a newer version:

# rpm -Uvh nameOfPackage.rpm

The command-line flags indicate (U)pgrading, (v)erbosity, and (h)ash marks.

Note that the -U switch will also install a package even if no prior version exists.

To install only if a prior version exists:

# rpm -Fvh nameOfPackage.rpm

The command-line flags indicate (F)reshen, (v)erbosity, and (h)ash marks.

This is useful if you've just e.g. downloaded all of the available updates for your distro, and you're not sure which packages you actually need to update. Just go into the directory with all the RPM files, and execute:

# rpm -Fvh *.rpm

Note: if you aren't sure what the '*.rpm' element of the command line refers to, please look at Filename Matching.

If you come across a stray RPM package, and you want to know what it is:

# rpm -qpi nameOfPackage.rpm

In addition - you can get a list of all the installed packages on your system with:

# rpm -qa

N.B - The rpm -qa "command" is often used in conjunction with grep when you want to focus on a "specific" package:

# rpm -qa | grep -i <your_string>

Installing source RPM packages

Source RPM packages still need to be compiled, so they are architecture-independant. Their names typically end in .src.rpm. To install them:

rpmbuild --rebuild <source package>

Afterwards, you can find your compiled package under /usr/src/packages/RPMS/i586 if you are on the i686 architecture.

Analyzing RPM packages

To view all files contained in an RPM package, use MidNightCommander.

Tips and Tricks

rpm -qa --last | tac

this prints all installed packages. tac is used to revert the order of the lines, so you have the latest package below, like this:

kdelibs3-devel-3.5.1-49.45                    Fri 05 Sep 2008 01:13:49 PM CEST
gpg-pubkey-9c800aca-481f343a                  Mon 08 Sep 2008 03:10:28 PM CEST
wireless-tools-28pre13-22.16.2                Mon 08 Sep 2008 03:11:56 PM CEST
wpa_supplicant-0.4.8-14.21.2                  Mon 08 Sep 2008 03:11:57 PM CEST
nxserver-3.2.0-16                             Fri 10 Oct 2008 04:03:24 PM CEST
  • To get a list of rpm-packages for that files are missing, use
rpm -qa | xargs rpm -ql | while read filename; do echo $filename; if [ -e $filename ]; then i=1; else echo "i would install  $(rpm -qf $filename | sed -r 's/-[0-9].*//')">>/tmp/uncompleterpms.log; fi; done 

Read /tmp/uncompleterpms.log to find out which packages were uncomplete.

See also