• Aucun résultat trouvé

The main RPM utility program is known as rpm. Use this program to install or upgrade a package at the shell prompt. The rpm command has the following syntax:

rpm [operation][options] [package-files|package-names]

Table 2.1 summarizes the most common rpm operations, and Table 2.2 summarizes the most important options. Be aware, however, that rpm is a complex tool, so this list-ing is necessarily incomplete. For information about operations and options more obscure than those listed in Tables 2.1 and 2.2, see the man pages for rpm. Many of rpm’s less-used features are devoted to the creation of RPM packages by software developers.

TA B L E 2 .1 Common rpm operations

Operation Description

-i Installs a package; system must not contain a package of the same name

-U Installs a new package or upgrades an existing one

-F or --freshen Upgrades a package only if an earlier version already exists -q Queries a package—finds whether a package is installed, what

files it contains, and so on

-V or --verify Verifies a package—checks that its files are present and unchanged since installation

-e Uninstalls a package

-b Builds a binary package, given source code and configuration files; moved to the rpmbuild program with RPM version 4.2 --rebuild Builds a binary package, given a source RPM file; moved to the

rpmbuild program with RPM version 4.2 --rebuilddb Rebuilds the RPM database to fix errors

52 Chapter 2 Managing Software

TA B L E 2 . 2 Most-important rpm options

Option Used with

operations

Description

--root dir Any Modifies the Linux system having a root directory located at dir. This option can be used to maintain one Linux installation discrete from another one (say, during OS installation or emergency

maintenance).

--force -i, -U, -F Forces installation of a package even when it means overwriting existing files or packages.

-h or --hash -i, -U, -F Displays a series of hash marks (#) to indicate the progress of the operation.

-v -i, -U, -F Used in conjunction with the -h option to produce a uniform number of hash marks for each package.

--nodeps -i, -U, -F, -e Specifies that no dependency checks be performed. Installs or removes the package even if it relies on a package or file that’s not present or is required by a package that’s not being uninstalled.

-p package-file -q Queries the uninstalled RPM package-file.

-i -q Displays package information, including

the package maintainer, a short description, and so on.

-R or --requires -q Displays the packages and files on which this one depends.

-l or --list -q Displays the files contained in the package.

c02.indd 52

c02.indd 52 11/12/12 12:01 PM11/12/12 12:01 PM

To use rpm, you combine one operation with one or more options. In most cases, you include one or more package names or package fi lenames as well. (A package fi lename is a complete fi lename, but a package name is a shortened version. For instance, a package fi le-name might be samba-3.6.5-86.fc17.1.x86_64.rpm, whereas the matching package name is samba.) You can issue the rpm command once for each package, or you can list multiple packages, separated by spaces, on the command line. The latter is often preferable when you’re installing or removing several packages, some of which depend on others in the group.

Issuing separate commands in this situation requires that you install the depended-on pack-age fi rst or remove it last, whereas issuing a single command allows you to list the packpack-ages on the command line in any order.

Some operations require that you give a package fi lename, and others require a package name. In particular, -i, -U, -F, and the rebuild operations require package fi lenames; -q, -V, and -e normally take a package name, although the -p option can modify a query (-q) operation to work on a package fi lename.

When you’re installing or upgrading a package, the -U operation is generally the most useful because it enables you to install the package without manually uninstalling the old one. This one-step operation is particularly helpful when packages contain many dependencies; rpm detects these and can perform the operation should the new package ful-fi ll the dependencies provided by the old one.

To use rpm to install or upgrade a package, issue a command similar to the following:

# rpm -Uvh samba-3.6.5-86.fc17.1.x86_64.rpm

You can also use rpm -ivh in place of rpm -Uvh if you don’t already have a samba package installed.

It’s possible to distribute the same program under different names. In this situation, upgrading may fail or it may produce a duplicate installa-tion, which can yield bizarre program-specific malfunctions. Red Hat has described a formal system for package naming to avoid such problems, but they still occur occasionally. Therefore, it’s best to upgrade a package using a subsequent release provided by the same individual or organiza-tion that provided the original.

Verify that the package is installed with the rpm -qi command, which displays

information such as when and on what computer the binary package was built. Listing 2.1 demonstrates this command. (rpm -qi also displays an extended plain-English summary of what the package is, which has been omitted from Listing 2.1.)

Listing 2.1: RPM query output

$ rpm -qi samba Name : samba Epoch : 2

54 Chapter 2 Managing Software

Version : 3.6.5 Release : 86.fc17.1 Architecture: x86_64

Install Date: Mon 16 Jul 2012 12:28:51 PM EDT Group : System Environment/Daemons Size : 18503445

License : GPLv3+ and LGPLv3+

Signature : RSA/SHA256, Fri 04 May 2012 11:03:50 AM EDT, Key ID«

50e94c991aca3465

Source RPM : samba-3.6.5-86.fc17.1.src.rpm Build Date : Fri 04 May 2012 08:42:51 AM EDT Build Host : x86-06.phx2.fedoraproject.org Relocations : (not relocatable)

Packager : Fedora Project Vendor : Fedora Project URL : http://www.samba.org/

Summary : Server and Client software to interoperate with Windows machines