Site icon Leonid Mamchenkov

Practical RPM

This document presents few practical tips for users of Redhat Pacakage Manager (RPM).


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 to most of RPM users.

Installation of new packages

# rpm -ivh vim-enhanced-6.1-14.i386.rpm

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 vim-enhanced-6.1-14.i386.rpm
  2. We want RPM to do upgrade only if the package is installed.
    # rpm -Fvh vim-enhanced-6.1-14.i386.rpm

Installation and/or upgrade of multiple packages
It is of course possible to install and/or upgrade multiple packages using shell wildcards.

# rpm -ivh vim*rpm 

Erasing (removing) packages

# rpm -e emacs


Intermidiate usage

Listing all installed packages

$ rpm -qa | sort

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 question 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 vim-enhanced.rpm file install?

$ rpm -qlp vim-enhanced.rpm

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 complete 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'

Listing installed packages sorted by size
RPM has an extremely useful –qf (query format) option, which allows you to specify 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. Rebuild RPM from source package can save you a lot of dependancy/compatibility troubles.

# rpmbuild --rebuild vim-6.1-14.src.rpm

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 now proceed with installation of the freshly built package.

Exit mobile version