• Aucun résultat trouvé

Yum (http://yum.baseurl.org), mentioned earlier, is one of several meta-packagers—it enables you to easily install a package and all its dependencies using a single command line.

When using Yum, you don’t even need to locate and download the package fi les, because Yum does this for you by searching in one or more repositories—Internet sites that host RPM fi les for a particular distribution.

Yum originated with the fairly obscure Yellow Dog Linux distribution, but it’s since been adopted by Red Hat, CentOS, Fedora, and some other RPM-based distributions.

Yum isn’t used by all RPM-based distributions, though; SUSE and Mandriva, to name just two, each use their own meta-packagers. Debian-based distributions generally employ the Advanced Package Tools (APT), as described later in “Using apt-get.” Nonetheless, because of the popularity of Red Hat, CentOS, and Fedora, knowing Yum can be valuable.

The most basic way to use Yum is with the yum command, which has the following syntax:

yum [options] [command] [package...]

Which options are available depend on the command you use. Table 2.3 describes common yum commands.

56 Chapter 2 Managing Software

TA B L E 2 . 3 Common yum commands

Command Description

install Installs one or more packages by package name. Also installs depen-dencies of the specified package or packages.

update Updates the specified package or packages to the latest available version.

If no packages are specified, yum updates every installed package.

check-update Checks to see whether updates are available. If they are, yum displays their names, versions, and repository area (updates or extras, for instance).

upgrade Works like update with the --obsoletes flag set, which handles obso-lete packages in a way that’s superior when performing a distribution version upgrade.

remove or erase Deletes a package from the system; similar to rpm -e, but yum also removes depended-on packages.

list Displays information about a package, such as the installed version and whether an update is available.

provides or whatprovides

Displays information about packages that provide a specified pro-gram or feature. For instance, typing yum provides samba lists all the Samba-related packages, including every available update. Note that the output can be copious.

search Searches package names, summaries, packagers, and descriptions for a specified keyword. This is useful if you don’t know a package’s name but can think of a word that’s likely to appear in one of these fields but not in these fields for other packages.

info Displays information about a package, similar to the rpm -qi command.

clean Cleans up the Yum cache directory. Running this command from time to time is advisable, lest downloaded packages chew up too much disk space.

shell Enters the Yum shell mode, in which you can enter multiple Yum commands one after another.

resolvedep Displays packages matching the specified dependency.

localinstall Installs the specified local RPM files, using your Yum repositories to resolve dependencies.

localupdate Updates the system using the specified local RPM files, using your Yum repositories to resolve dependencies. Packages other than those updated by local files and their dependencies are not updated.

deplist Displays dependencies of the specified package.

c02.indd 56

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

In most cases, using Yum is easier than using RPM directly to manage packages, because Yum fi nds the latest available package, downloads it, and installs any required dependencies.

Yum has its limits, though; it’s only as good as its repositories, so it can’t install software that’s not stored in those repositories.

If you use Yum to automatically upgrade all packages on your system, you’re effectively giving control of your system to the distribution

maintainer. Although Red Hat or other distribution maintainers are unlikely to try to break into your computer in this way, an automatic update with minimal supervision on your part could easily break something on your system, particularly if you’ve obtained packages from unusual sources in the past.

If you don’t want to install the package but merely want to obtain it, you can use yumdownloader. Type this command followed by the name of a package, and the latest version of the package will be downloaded to the current directory. This can be handy if you need to update a system that’s not connected to the Internet; you can use another computer that runs the same distribution to obtain the packages and then transfer them to the target system.

If you prefer to use GUI tools rather than command-line tools, you should be aware that GUI front-ends to yum exist. Examples include yumex and kyum. You can use the text-mode yum to install these front-ends, as in yum install kyum.

Exercise 2.1 runs you through the process of managing packages using the rpm utility.

E X E R C I S E 2 . 1

Managing Packages Using RPM

To manage packages using the rpm utility, follow these steps:

1. Log into the Linux system as a normal user.

2. Acquire a package to use for testing purposes. You can try using a package from your distribution that you know you haven’t installed; but if you try a random package, you may fi nd it’s already installed or has unmet dependencies. This lab uses as an example the installation of zsh-4.3.17-1.fc17.x86_64.rpm, a shell that’s not installed by default on most systems, from the Fedora 17 DVD onto a Fedora 17 system. You must adjust the commands as necessary if you use another RPM fi le in your tests.

3. Launch an xterm from the desktop environment’s menu system if you used a GUI login.

4. Acquire root privileges. You can do this by typing su in an xterm, by selecting Session New Root Console from a Konsole window, or by using sudo (if it’s confi gured) to run the commands in the following steps.

58 Chapter 2 Managing Software

E X E R C I S E 2 . 1 ( c o n t i n u e d )

5. Type rpm -q zsh to verify that the package isn’t currently installed. The system should respond with the message package zsh is not installed.

6. Type rpm -qpi zsh-4.3.17-1.fc17.x86_64.rpm. (You’ll need to provide a complete path to the package fi le if it’s not in your current directory.) The system should respond by displaying information about the package, such as the version number, the vendor, the hostname of the machine on which it was built, and a package description.

7. Type rpm -ivh zsh-4.3.17-1.fc17.x86_64.rpm. The system should install the package and display a series of hash marks (#) as it does so.

8. Type rpm -q zsh. The system should respond with the complete package name, including the version and build numbers. This response verifi es that the package is installed.

9. Type zsh. This launches a Z shell, which functions much like the more common bash and tcsh shells. You’re likely to see your command prompt change, but you can issue most of the same commands you can use with bash or tcsh.

10. Type rpm -V zsh. The system shouldn’t produce any output—just a new command prompt. The verify (-V or --verify) command checks the package fi les against data stored in the database. Immediately after installation, most packages should show no deviations. (A handful of packages will be modifi ed during installation, but zsh isn’t one of them.)

11. Type rpm -e zsh. The system shouldn’t produce any output—just a new command prompt. This command removes the package from the system. Note that you’re removing the zsh package while running the zsh program. Linux continues to run the zsh program you’re using, but you’ll be unable to launch new instances of the program.

Some programs may misbehave if you do this because fi les will be missing after you remove the package.

12. Type exit to exit zsh and return to your normal shell.

13. Type rpm -q zsh. The system should respond with a package zsh is not installed error because you’ve just uninstalled the package.

14. Type yum install zsh. The system should check your repositories, download zsh, and install it. It will ask for confi rmation before beginning the download.

15. Type rpm -q zsh. The results should be similar to those in step 8, although the version number may differ.

16. Type rpm -e zsh. This step removes zsh from the system but produces no output, just as in step 11.

The fi nal three steps will work only if your distribution uses Yum. If you’re using a distribution that uses another tool, you may be able to locate and use its equivalent, such as zypper for SUSE.

c02.indd 58

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