This chapter describes the two major Linux packaging systems: the Red Hat Package Manager (RPM) and the Debian GNU/Linux Package Manager.
When you install applications on your Linux system, most often you'll find a binary or a source package containing the application you want, instead of (or in addition to) a .tar.gz file. A package is a file containing the files necessary to install an application. However, while the package contains the files you need for installation, the application might require the presence of other files or packages that are not included, such as particular libraries (and even specific versions of the libraries), to actually be able to run. Such requirements are known as dependencies.
Package management systems offer many benefits. As a user, you may want to query the package database to find out what packages are installed on the system and their versions. As a system administrator, you need tools to install and manage the packages on your system. And if you are a developer, you need to know how to build a package for distribution.
Among other things, package managers do the following:
Provide tools for installing, updating, removing, and managing the software on your system.
Allow you to install new or upgraded software directly across a network.
Tell you what software package a particular file belongs to or what files a package contains.
Maintain a database of packages on the system and their state, so you can find out what packages or versions are installed on your system.
Provide dependency checking, so you don't mess up your system with incompatible software.
Provide PGP, MD5, or other signature verification tools.
Provide tools for building packages.
Any user can list or query packages. However, installing, upgrading, or removing packages generally requires superuser privileges. This is because the packages normally are installed in systemwide directories that are writable only by root. Sometimes you can specify an alternate directory to install a package into your home directory or into a project directory where you have write permission.
Both RPM and the Debian Package Manager back up old files before installing an updated package. Not only does this let you go back if there is a problem, but also ensures that you don't lose your changes (to configuration files, for example).
The Red Hat Package Manager (RPM) is a freely available packaging system for software distribution and installation. In addition to Red Hat and Red Hat-based distributions, both SuSE and Caldera are among the Linux distributions that use RPM.
Using RPM is straightforward. A single command, rpm, has options to perform all package management functions except building packages.[7] For example, to find out if the Emacs editor is installed on your system, you could say:
[7]In older versions of RPM, the build options were part of the rpm command.
% rpm -q emacs emacs-21.2-18
The rpmbuild command is used to build both binary and source packages.
RPM packages are built, installed, and queried with the rpm command. RPM package names usually end with a .rpm extension. rpm has a set of modes, each with its own options. The format of the rpm command is:
rpm [options] [packages]
With a few exceptions, as noted in the lists of options that follow, the first option specifies the rpm mode (install, query, update, etc.), and any remaining options affect that mode.
Options that refer to packages are sometimes specified as package-name and sometimes as package-file. The package name is the name of the program or application, such as gif2png. The package file is the name of the RPM file, such as gif2png-2.4.6-1.i386.rpm.
RPM provides a configuration file for specifying frequently used options. The default global configuration is usually /usr/lib/rpm/rpmrc, the local system configuration file is /etc/rpmrc, and users can set up their own $HOME/.rpmrc files. You can use the --showrc option to show the values RPM will use for all the options that may be set in an rpmrc file:
rpm --showrc
The rpm command includes FTP and HTTP clients, so you can specify an ftp:// or http:// URL to install or query a package across the Internet. You can use an FTP or HTTP URL wherever package-file is specified in the commands presented here.
Any user can query the RPM database. Most of the other functions require superuser privileges.
The following options can be used with all modes:
Use the install command to install or upgrade an RPM package. The install syntax is:
rpm -i [install-options] package_file ... rpm --install [install-options] package_file ...
To install a new version of a package and remove an existing version at the same time, use the upgrade command instead:
rpm -U [install-options] package_file ... rpm --upgrade [install-options] package_file ...
If the package doesn't already exist on the system, -U acts like -i and installs it. To prevent that behavior, you can freshen a package instead; in that case, rpm upgrades the package only if an earlier version is already installed. The freshen syntax is:
rpm -F [install-options] package_file ... rpm --freshen [install-options] package_file ...
package-file can be specified as an FTP or HTTP URL to download the file before installing it. See Section 5.1.1.11.
The installation and upgrade options are:
The syntax for the query command is:
rpm -q [package-options] [information-options] rpm --query [package-options] [information-options]
There are two subsets of query options. Package selection options determine what packages to query, and information selection options determine what information to provide.
%{NAME}
The tag names are case-insensitive. Use --querytags (see Section 5.1.1.10) to view a list of available tags. The tag can be followed by :type to get a different output format type. The possible types are:
path size mtime md5sum mode owner group isconfig isdoc rdev symlink
The syntax for erase, the uninstall command, is:
rpm -e package_name ... rpm --erase package_name ...
The uninstall options are:
The syntax for the verify command is:
rpm -V|-y|--verify [package-selection-options] [verify-options]
Verify mode compares information about the installed files in a package with information about the files that came in the original package, and displays any discrepancies. The information compared includes the size, MD5 sum, permissions, type, owner, and group of each file. Uninstalled files are ignored.
The package selection options include those available for query mode. In addition, the following verify options are available:
The output is formatted as an eight-character string, possibly followed by an attribute marker, and then the filename. The possible attribute markers are:
c |
Configuration file |
d |
Documentation file |
g |
Ghost file (contents not included in package) |
l |
License file |
r |
Readme file |
Each of the eight characters in the string represents the result of comparing one file attribute to the value of that attribute from the RPM database. A period (.) indicates that the file passed that test. The following characters indicate failure of the corresponding test:
5 |
MD5 sum |
D |
Device |
G |
Group |
L |
Symlink |
M |
Mode (includes permissions and file type) |
S |
File size |
T |
Mtime |
U |
User |
The syntax of the command to rebuild the RPM database is:
rpm --rebuilddb [options]
You also can build a new database:
rpm --initdb [options]
The options available with the database rebuild mode are the --dbpath, --root, and -v options described earlier under Section 5.1.1.1.
RPM packages may have a PGP signature built into them. PGP configuration information is read from the rpmrc file. There are three types of digital signature options: you can check signatures, add signatures to packages, and import signatures.
The syntax of the signature check mode is:
rpm --checksig package_file... rpm -K package_file...
The signature checking options -K and --checksig check the digests and signatures contained in the specified packages to insure the integrity and origin of the packages. Note that RPM now automatically checks the signature of any package when it is read; this option is still useful, however, for checking all headers and signatures associated with a package.
The following options are available for use with signature check mode:
The syntax for adding signatures to binary packages is:
rpm --addsign binary-pkgfile... rpm --resign binary-pkgfile...
Both --addsign and --resign generate and insert new signatures, replacing any that already exist in the specified binary packages.[8]
[8]In older versions of RPM, --addsign was used to add new signatures without replacing existing ones, but currently both options work the same way and replace any existing signatures.
The syntax for importing signatures is:
rpm --import public-key
The --import option is used to import an ASCII public key to the RPM database so that digital signatures for packages using that key can be verified. Imported public keys are carried in headers, and keys are kept in a ring, which can be queried and managed like any package file.
Several additional rpm options are available:
The following options are available for use with FTP and HTTP URLs in install, update, and query modes.
The rpmbuild command is used to build RPM packages. The syntax for rpmbuild is:
rpmbuild -[b|t]step [build-options] spec-file ...
Specify -b to build a package directly from a spec file, or -t to open a tarred, gzipped file and use its spec file.
Both forms take the following single-character step arguments, listed in the order they would be performed:
The general rpm options described earlier in Section 5.1.1.1 can be used with rpmbuild.
The following additional options can also be used when building an rpm file with rpmbuild:
Two other options can be used standalone with rpmbuild to recompile or rebuild a package:
Finally, the --showrc option is used to show the current rpmbuild configuration:
rpmbuild --showrc
This option shows the values that will be used for all options that can be set in an rpmrc file.
Query the RPM database to find Emacs-related packages:
% rpm -q -a | grep emacs
Query an uninstalled package, printing information about the package and listing the files it contains:
% rpm -qpil ~/downloads/bash2-doc-2.03-8.i386.rpm
Install a package (assumes superuser privileges):
% rpm -i sudo-1.5.3-6.i386.rpm
Copyright © 2003 O'Reilly & Associates. All rights reserved.