| back to homepage | using rpm |
Using rpm
The rpm basic commands
An overview of the most used commands
Querying
Using rpm
RPM has five basic modes of operation (not counting package building):
installing, uninstalling, upgrading, querying, and verifying. This section
contains an overview of each mode. For complete details and options try
rpm --help, or turn to
the section called Other RPM Resources for more information on RPM.
Check before install
Before installation of a package: check if the package is already installed.
Check if packages are already installed can be done with the following command:
rpm -qa | egrep '(wu-ftpd|anonftp)'
If the packages are not installed, they can be installed from the Red Hat Linux installation cd, as the root user:
mount /mnt/cdrom cd /mnt/cdrom/RedHat/RPMS/ rpm -ivh wu-ftpd* anonftp* cd umount /mnt/cdrom
# rpm -ivh foo-1.0-1.i386.rpm foo #################################### #
As you can see, RPM prints out the name of the package (which is not necessarily the same as the file name, which could have been 1.rpm) and then prints a succession of hash marks as the package is installed, as a progress meter.
Note
Although using the command rpm -ivh foo-1.0-1.i386.rpm
to install is common, you may want to consider using
rpm -Uvh foo-1.0-1.i386.rpm instead. -U is commonly used
for upgrading a package, but it will also install new packages. See
the section called Upgrading for more information about using the
-U RPM command.
Installing packages is designed to be simple, but you can get a few errors:
Package Already Installed
If the package is already installed, you will see:
rpm -ivh foo-1.0-1.i386.rpm foo package foo-1.0-1 is already installed error: foo-1.0-1.i386.rpm cannot be installed
If you really want to install the package anyway, you can use --replacepkgs on the command line, which tells RPM to ignore the error:
# rpm -ivh --replacepkgs foo-1.0-1.i386.rpm foo #################################### #
Conflicting files
If you attempt to install a package that contains a file which has already been installed
by another package, you'll see:
# rpm -ivh foo-1.0-1.i386.rpm foo /usr/bin/foo conflicts with file from bar-1.0-1 error: foo-1.0-1.i386.rpm cannot be installed #
To cause RPM to ignore that error, use --replacefiles on the command line:
# 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 for which there is such an unresolved dependency, you'll see:
# rpm -ivh bar-1.0-1.i386.rpm
failed dependencies:
foo is needed by bar-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 --nodeps on the command line.
See dependencies
RPM packages can "depend" on other packages, which means that they require
If you want to know the dependency before install RPM, use
# rpm -qRp <RPM_package.rpm>
This command tells you the dependency file name of the RPM.
If you want to find some RPMs, I advice you to check your distribution web site or http://rpmfind.net
Uninstalling
Uninstalling a package is just as simple as installing:
# rpm -e foo #
Note
Notice that we used the package name "foo" not the name of the original
package file "foo-1.0-1.i386.rpm". To uninstall a package, you will need
to replace foo with the actual filename of the original package.
You can encounter a dependency error when uninstalling a package if some other 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 that 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 --nodeps on the command line.
# rpm -Uvh foo-2.0-1.i386.rpm foo #################################### #
What you don't see above is that RPM automatically uninstalled any old versions of the foo package. In fact you may want to always use -U to install packages, since it works fine even when there are no previous versions of the package installed.
Since RPM performs intelligent upgrading of packages with configuration files, you may see a message like:
saving /etc/foo.conf as /etc/foo.conf.rpmsave
This means that your changes to the configuration file may not be "forward compatible" with the new configuration file in the package, so RPM saved your original file, and installed a new one. You should investigate and resolve the differences between the two files as soon as possible to ensure that your system continues to function properly.
Since upgrading is really a combination of uninstalling and installing, you can encounter any errors from those modes, 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 error: foo-1.0-1.i386.rpm cannot be installed #
To cause RPM to "upgrade" anyway, use --oldpackage on the command line:
# rpm -Uvh --oldpackage foo-1.0-1.i386.rpm foo #################################### #
# rpm -Fvh foo-1.2-1.i386.rpm foo #################################### #
RPM's freshen option checks the versions of the packages specified on the command line against the versions of packages that have already been installed on your system. When a newer version of an already-installed package is processed by RPM's freshen option, it will be upgraded to the newer version. However, RPM's freshen option will not install a package if no previously-installed package of the same name exists. This differs from RPM's upgrade option, as an upgrade will install packages, whether or not an older version of the package was already installed.
RPM's freshen option works well with single packages or with a group of packages. It's especially handy if you've just downloaded a large number of different packages, and you only want to upgrade those packages that are already installed on your system. Using the freshen option means that you won't have to pick through the downloaded packages, deleting any unwanted ones before using RPM.
In this case, you can simply issue the following command:
# rpm -Fvh *.rpm
RPM will automatically upgrade only those packages that have already been installed.
# 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.
For those options that display file lists, you can add -v to your command line to get the lists in a familiar ls -l format.
The command rpm -V verifies a package. You can use any of the Package Selection Options listed for querying to specify the packages you wish to verify. A simple use is rpm -V foo which verifies that all the files in the foo package are as they were when they were originally installed. For example:
This can be useful if you suspect that your RPM databases are corrupt!
andere syntax, check ...
rpm -Va --pipe "awk '{print $2}' | xargs rpm -qf | sort -u" &> /tmp/file1
Then look in the file /tmp/file1 for the list of packages that were changed.
If everything verified properly there will be no output. If there are any discrepancies they will be displayed. The format of the output is a string of 8 characters, a possible "c" denoting a configuration file, and then the file name. Each of the 8 characters denotes the result of a comparison of one attribute of the file to the value of that attribute recorded in the RPM database. A single "." (period) means the test passed. The following characters denote failure of certain tests:
If you see any output, use your best judgment to determine if you should remove or reinstall the package, or otherwise fix the problem.
rpm -Va
If some files are missing, or appear to have been corrupted, you should probably either re-install the package or uninstall, then re-install the package.
rpm -qf /usr/X11R6/bin/ghostview
The output would look like:
gv-3.5.8-10
rpm -Vf /usr/bin/paste
and the appropriate package will be verified.
rpm -qdf /usr/bin/md5sum
The output would be:
/usr/share/doc/textutils-2.0a/NEWS /usr/share/doc/textutils-2.0a/README /usr/info/textutils.info.gz /usr/man/man1/cat.1.gz /usr/man/man1/cksum.1.gz /usr/man/man1/comm.1.gz /usr/man/man1/csplit.1.gz /usr/man/man1/cut.1.gz /usr/man/man1/expand.1.gz /usr/man/man1/fmt.1.gz /usr/man/man1/fold.1.gz /usr/man/man1/head.1.gz /usr/man/man1/join.1.gz /usr/man/man1/md5sum.1.gz /usr/man/man1/nl.1.gz /usr/man/man1/od.1.gz /usr/man/man1/paste.1.gz /usr/man/man1/pr.1.gz /usr/man/man1/ptx.1.gz /usr/man/man1/sort.1.gz /usr/man/man1/split.1.gz /usr/man/man1/sum.1.gz /usr/man/man1/tac.1.gz /usr/man/man1/tail.1.gz /usr/man/man1/tr.1.gz /usr/man/man1/tsort.1.gz /usr/man/man1/unexpand.1.gz /usr/man/man1/uniq.1.gz /usr/man/man1/wc.1.gz
rpm -qip sndconfig-0.48-1.i386.rpm
The output would be:
Name : sndconfig Relocations: (not relocateable) Version : 0.48 Vendor: Red Hat Release : 1 Build Date: Mon 10 Jul 2000 02:25:40 Install date: (none) Build Host: porky.devel.redhat.com Group : Applications/Multimedia Source RPM: sndconfig-0.48-1.src.rpm Size : 461734 License: GPL Packager : Red Hat <http://bugzilla.redhat.com/bugzilla> Summary : The Red Hat Linux sound configuration tool. Description : Sndconfig is a text based tool which sets up the configuration files you'll need to use a sound card with a Red Hat Linux system. Sndconfig can be used to set the proper sound type for programs which use the /dev/dsp, /dev/audio and /dev/mixer devices. The sound settings are saved by the aumix and sysV runlevel scripts.
rpm -qlp sndconfig-0.48-1.i386.rpm
The output is:
/usr/sbin/pnpprobe /usr/sbin/sndconfig /usr/share/locale/cs/LC_MESSAGES/sndconfig.mo /usr/share/locale/da/LC_MESSAGES/sndconfig.mo /usr/share/locale/de/LC_MESSAGES/sndconfig.mo /usr/share/locale/es/LC_MESSAGES/sndconfig.mo /usr/share/locale/fr/LC_MESSAGES/sndconfig.mo /usr/share/locale/hu/LC_MESSAGES/sndconfig.mo /usr/share/locale/id/LC_MESSAGES/sndconfig.mo /usr/share/locale/is/LC_MESSAGES/sndconfig.mo /usr/share/locale/it/LC_MESSAGES/sndconfig.mo /usr/share/locale/ko/LC_MESSAGES/sndconfig.mo /usr/share/locale/no/LC_MESSAGES/sndconfig.mo /usr/share/locale/pt/LC_MESSAGES/sndconfig.mo /usr/share/locale/pt_BR/LC_MESSAGES/sndconfig.mo /usr/share/locale/ro/LC_MESSAGES/sndconfig.mo /usr/share/locale/ru/LC_MESSAGES/sndconfig.mo /usr/share/locale/sk/LC_MESSAGES/sndconfig.mo /usr/share/locale/sl/LC_MESSAGES/sndconfig.mo /usr/share/locale/sr/LC_MESSAGES/sndconfig.mo /usr/share/locale/sv/LC_MESSAGES/sndconfig.mo /usr/share/locale/tr/LC_MESSAGES/sndconfig.mo /usr/share/locale/uk/LC_MESSAGES/sndconfig.mo /usr/share/man/man8/pnpprobe.8.gz /usr/share/man/man8/sndconfig.8.gz /usr/share/sndconfig/sample.au /usr/share/sndconfig/sample.midi
Other RPM Resources
For more information on RPM, check out the man page, the help screen
(rpm --help), and the RPM documents available at
http://www.rpm.org/
There is also an RPM book available. It's called Maximum RPM, and it is available from Red Hat, at your local bookstore and through online booksellers. It contains a wealth of information about RPM for both the end-user and the package builder.
There is also a mailing list for discussion of RPM-related issues, called [email protected]
The list is archived on http://www.redhat.com/support/mailing-lists/.
To subscribe, send mail to [email protected]
with the word subscribe in the subject line.
A: The problem is that a very few earlier versions of RPM would write the database in a way that seems corrupted to later versions. Rebuilding the database fixes the install problems. You will need to upgrade the RPM application on your system to the one on the installation CD-ROM, and rebuild the databases.
The first thing to do is mount the first Red Hat Linux installation CD-ROM on the system.
mount /mnt/cdrom
After doing this, upgrade the RPM application using the latest version on the CD-ROM:
cd /mnt/cdrom/RedHat/RPMS rpm -Uvh --nodeps --force rpm-*rpm
When the new RPM application is installed, rebuild the RPM database.
rpm --rebuilddb
This will put the RPM database in a format that the RPM application used by the Red Hat Linux installation program can use (since they are the same).
Last update: 29-11-2003