Practical RPM
Leonid Mamtchenkov
This document presents few practical tips for users of Redhat Pacakage Manager (RPM).
Table of Contents
Introduction ...........................................................................................................................3
Simple usage..........................................................................................................................3
Intermidiate usage ................................................................................................................3
Advanced usage ....................................................................................................................4
Introduction
This document will not cover or explain any theory behind RPM, since it has been
nicely done in few other documents. Please consider reading man rpm for a general
list of options and RPM-Howto for the theory part. RPM-Howto is mostly oriented
towards building RPMs from source, but it is still a good read.
Simple usage
This section provides some simple examples of RPM usage. Most of these actions
happen on a daily basis and should be familiar for most of RPM users.
Installation of new packages
# rpm -ivh [Link]
Upgrading of packages
There are two distinct scenarios when upgrading packages:
1. We want RPM to check if the package is installed and if it is, then upgrade it.
If the package is not intalled, then install it.
# rpm -Uvh [Link]
2. We want RPM to do upgrade only if the package is installed.
# rpm -Fvh [Link]
Installation and/or upgrade of multiple packages
It is of course possible to install and/or upgrade multiple packages using shell wild-
cards.
# rpm -ivh vim*rpm
Erasing (removing) packages
# rpm -e emacs
Intermidiate usage
Listing all installed packages
$ rpm -qa | sort
3
Practical RPM
Selective listing of installed packages
Sometimes one may need to find all installed packages that match some pattern, like
“kernel” or “vim”. This task can be completed using the following command.
$ rpm -qa | grep -i vim
Asking questions about files
If you do not recognize a file on your system, then RPM can be queried to inform you
of any package that installed that file.
$ rpm -qf /usr/bin/vim
Sometimes you would want to see a list of all files installed by certain package.
$ rpm -ql vim-enhanced
With a little more grep magic you can find out about all programs that the package
in quetion installed.
$ rpm -ql vim-enhanced | grep bin
Advanced usage
Package requirements
RPM is well-known for its dependecies headaches. It is, therefor, often important to
see what the package requires:
$ rpm -q --requires vim-enhanced
and/or what it provides:
$ rpm -q --provides vim-enhanced
Quering not installed packages
Sometimes it is desirable to query RPM files before installing them. This can be done
by adding -p to the query and specifying the filename of the package in question.
For example, what will the [Link] file install?
$ rpm -qlp [Link]
More shell magic
Let’s erase all packages which have “emacs” in their names.
$ rpm -e ‘ rpm -qa | grep -i emacs ‘
Quering for package groups
Each and every RPM package belongs to a predefined group of packages. The com-
plete list of all groups is can be found in RPM-Howto. Below is an example of a query
for the packages which are in “Applications/Editors” group.
$ rpm -q --group "Applications/Editors"
4
Practical RPM
Listing installed packages sorted by size
RPM has an extremely useful --qf (query format) option, which allows you to spec-
ify exactly how do you want the results of the query to appear. It is very similar in
syntax to the traditional printf command. Additionally, it allows you to use any of
the RPM information fields in your query, like “SIZE”, “NAME”, “VERSION”, etc.
$ rpm -qa --qf "%-10{SIZE} %-30{NAME}\n" | sort -n
Crash/malfunction recovery helpers
RPM is a very useful tool in case you had your system crashed and/or compromised.
For example, in case your apache stopped working for some reason, you can easily
check which files are missing or were changed.
$ rpm --verify ‘ rpm -qa | grep -i apache ‘
In case you accidentally changed mode (permissions) of a file and you want to bring
it to the original state without doing a timely restore from tape, --dump gets handy.
Below is an example of retreiving original mode for /bin/bash file from the RPM
database.
$ rpm -q --dump bash | grep "/bin/bash"
Building packages from source RPMs
Most of the times, RPM packages are provided in both binary and source form. Re-
build RPM from source package can save you a lot of dependancy/compatibility
troubles.
# rpmbuild --rebuild [Link]
If everything went fine, then you will find the resulting RPM in
/usr/src/redhat/RPMS/i386/ directory (or the one appropriate for your
distribution and architecture). You can proceed with installation of the freshly built
package as discussed in “Installation of new packages”.
5
Practical RPM