Книга: Fedora™ Unleashed, 2008 edition
Using rpm on the Command Line
Using rpm
on the Command Line
Although several GUI clients make use of rpm
, you can perform all five basic rpm
operations by using the rpm command from the command line. This section gives you an introduction to performing those operations. It also provides examples of how to install, verify, query, remove, and upgrade a software package.
The most common rpm
operation is software installation. Using rpm
is an easy way to keep track of installed software, and it can be used to quickly remove undesired packages. Use the -i
option, along with the full or partial name (using regular expressions) of a software package, to install software with rpm
. For example, to install the RPM file for configuring the usage of the FreshRPMs repository, use the rpm
command like this:
# rpm -ivh http://ftp.freshrpms.net/pub/freshrpms/fedora/linux/
8/freshrpms-release/freshrpms-release-1.1-1.fc.noarch.rpm
Retrieving http://ftp.freshrpms.net/pub/freshrpms/fedora/linux/
7/freshrpms-release/freshrpms-release-1.1-1.fc.noarch.rpm
warning: /var/tmp/rpm-xfer.48amVs: V3 DSA signature: NOKEY, key ID 8df56d05
Preparing... ########################################### [100%]
1:freshrpms-release
########################################### [100%]
This example uses the v
and h
options, which provide a more verbose output and display of hash marks to show the progress of the installation. The example also demonstrates the capability of rpm to use HTTP or FTP servers to fetch files for installation. It also shows that rpm
can use GPG keys to validate a file. (The key was not installed in the example.)
You can also use rpm
to query its database after installing packages to verify an installation. Use the -V
option, along with the name of a software package, to verify installation of your system. For example, to verify the freshrpms-release
package, use the rpm
command like this:
# rpm -V freshrpms-release
NOTE
If everything is correct with your software installation, your system displays no response to rpm -V
after you run the command; only problems are displayed.
As you can see from the following program output, you can get additional information about a package by adding additional verification options (such as two more v
's) to the -V
option. To get more information about an installed package, use one or more forms of the rpm
query options. For example, to display concise information about an installed package, use the -q
option, along with the i
option and the installed package name, like this. (Note that your version will differ from that shown here.)
# rpm -qi yum
Name : yum Relocations: (not relocatable)
Version : 3.2.7 Vendor: Fedora Project
Release : 1.fc8 Build Date: Fri 12 Oct 2007 09:22:34 PM BST
Install Date: Sun 21 Oct 2007 05:20:19 PM BST Build Host: ppc3.fedora.redhat.com
Group : System Environment/Base Source RPM: yum-3.2.7-1.fc8.src.rpm
Size : 1712619 License: GPLv2+
Signature : (none)
Packager : Fedora Project
URL : http://linux.duke.edu/yum/
Summary : RPM installer/updater
Description :
Yum is a utility that can check for and automatically download and
install updated RPM packages. Dependencies are obtained and downloaded
automatically prompting the user as necessary.
This form of the rpm
query provides quite a bit of information about the software package. (You can also query packages before installation by providing a pathname for them.)
If this package is not up-to-date, you can easily and quickly upgrade the package by downloading a newer version and then using rpm
's -U
or upgrade option like this:
# rpm -Uvh yum-3.2.0-1.fc8.rpm
Preparing... ########################################### [100%]
1:yum ########################################### [100%]
Note that it was not necessary to remove the currently installed software package — the U
option removes the old version of the software (saving the old configuration files), and then automatically installs the new software.
You can also upgrade your system software by using the rpm
command's -F
or "freshen" option, which fetches a designated package from a remote FTP or HTTP server. For example, to upgrade the fetchmail-conf
package, use rpm
like this:
# rpm -Fv ftp://ftp.tux.org/linux/redhat/updates/9/en/os/i386/
initscripts-7.14-1.i386.rpm
Retrieving ftp://ftp.tux.org/linux/redhat/updates/9/en/os/i386/
initscripts-7.14-1.i386.rpm
Preparing packages for installation...
initscripts-7.14-1
Use the -e
option, along with the name of a software package, to remove or erase software from your system with rpm
. For example, to remove the unace
archiving package, use the rpm
command like this:
# rpm -e unace
Note that if the operation succeeds, no messages are displayed on your system. You can quickly search for the names of installed packages by piping the output of rpm -qa
through the grep
and sort
commands (see Chapter 4, "Command-Line Quick Start," for additional information on grep
and sort
); here's how to do that search:
# rpm -qa | grep mail | sort
fetchmail-6.3.8-3.fc8
mailcap-2.1.25-1.fc8
mailx-8.1.1-46.fc7
procmail-3.22-20.fc8
sendmail-8.14.1-4.2.fc8
This example returns a sorted list of all packages with names containing the word mail
.
NOTE
Another essential feature of the rpm
command is its --rebuilddb
option. If your system's RPM database becomes corrupted, this is your first (and perhaps only) option for restoring software management services. We hope that you never have to use this option; help ensure that by always backing up your data!
- rpm at the Command Line
- QLineEdit
- 4.4.4 The Dispatcher
- About the author
- Chapter 7. The state machine
- Appendix A. Detailed explanations of special commands
- Appendix E. Other resources and links
- Caveats using NAT
- Example NAT machine in theory
- Using Double Quotes to Resolve Variables in Strings with Embedded Spaces
- The final stage of our NAT machine
- Compiling the user-land applications