• Aucun résultat trouvé

very useful when you want to install several packages, but dpkg is often more convenient when you’re manipulating just one or two packages. Because dpkg can take package fi le-names as input, it’s also the preferred method of installing a package that you download from an unusual source or create yourself.

Using apt-cache

The APT suite of tools includes a program, apt-cache, that’s intended solely to provide information about the Debian package database (known in Debian terminology as the package cache). You may be interested in using several features of this tool:

Display Package Information Using the showpkg subcommand, as in apt-cache showpkg samba, displays information about the package. The information displayed is different from that returned by dpkg’s informational actions.

Display Package Statistics You can learn how many packages you’ve installed, how many dependencies are recorded, and various other statistics about the package database by passing the stats subcommand, as in apt-cache stats.

Find Unmet Dependencies If a program is reporting missing libraries or fi les, typing apt-cache unmet may help; this function of apt-cache returns information about unmet dependencies, which may help you track down the source of missing-fi le problems.

Display Dependencies Using the depends subcommand, as in apt-cache depends samba, shows all of the specifi ed package’s dependencies. This information can be helpful in tracking down dependency-related problems. The rdepends subcommand fi nds reverse dependencies—packages that depend on the one you specify.

Locate All Packages The pkgnames subcommand displays the names of all the packages installed on the system. If you include a second parameter, as in apt-cache pkgnames sa, the program returns only those packages that begin with the specifi ed string.

Several more subcommands and options exist, but these are the ones you’re most likely to use. Several apt-cache subcommands are intended for package maintainers and debugging serious package database problems rather than day-to-day system administration. Consult the man page for apt-cache for more information.

Using apt-get

APT, with its apt-get utility, is Debian’s equivalent to Yum on certain RPM-based distributions. This meta-packaging tool enables you to perform easy upgrades of pack-ages, especially if you have a fast Internet connection. Debian-based systems include a fi le, /etc/apt/sources.list, that specifi es locations from which important packages can be obtained. If you installed the OS from a CD-ROM drive, this fi le will initially

66 Chapter 2 Managing Software

list directories on the installation CD-ROM in which packages can be found. There are also likely to be a few lines near the top, commented out with hash marks (#), indicating directories on an FTP site or a Web site from which you can obtain updated packages.

(These lines may be uncommented if you did a network install initially.)

Don’t add a site to /etc/apt/sources.list unless you’re sure it can be trusted. The apt-get utility does automatic and semiautomatic upgrades, so if you add a network source to sources.list and that source contains unreliable programs or programs with security holes, your system will become vulnerable after upgrading via apt-get.

Although APT is most strongly associated with Debian systems, a port to RPM-based systems is also available. Check http://apt4rpm.sourceforge.net for information about this port.

The apt-get utility works by obtaining information about available packages from the sources listed in /etc/apt/sources.list and then using that information to upgrade or install packages. The syntax is similar to that of dpkg:

apt-get [options][command] [package-names]

Table 2.6 lists the apt-get commands, and Table 2.7 lists the most commonly used options. In most cases, you won’t use any options with apt-get—just a single command and possibly one or more package names. One particularly common use of this utility is to keep your system up to date with any new packages. The following two commands will accomplish this goal if /etc/apt/sources.list includes pointers to up-to-date fi le archive sites:

# apt-get update

# apt-get dist-upgrade

TA B L E 2 . 6 apt-get commands

Command Description

update Obtains updated information about packages available from the installation sources listed in /etc/apt/sources.list.

upgrade Upgrades all installed packages to the newest versions available, based on locally stored information about available packages.

dselect-upgrade Performs any changes in package status (installation, removal, and so on) left undone after running dselect.

c02.indd 66

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

dist-upgrade Similar to upgrade, but performs “smart” conflict resolution to avoid upgrading a package if doing so would break a dependency.

install Installs a package by package name (not by package filename), obtaining the package from the source that contains the most up-to-date version.

remove Removes a specified package by package name.

source Retrieves the newest available source package file by package file-name using information about available packages and installation archives listed in /etc/apt/sources.list.

check Checks the package database for consistency and broken package installations.

clean Performs housekeeping to help clear out information about retrieved files from the Debian package database. If you don’t use dselect for package management, run this from time to time in order to save disk space.

autoclean Similar to clean but removes information only about packages that can no longer be downloaded.

Downloads package files but doesn’t install them.

-f or --fix-broken install, remove Attempts to fix a system on which dependencies are unsatisfied.

Ignores all package files that can’t be retrieved (because of network errors, missing files, or the like).

-q or --quiet All Omits some progress indicator information.

May be doubled (for instance, -qq) to

All Performs a simulation of the action without actually modifying, installing, or removing files.

68 Chapter 2 Managing Software

TA B L E 2 . 7 Most-useful apt-get options (continued)

Option Used with

commands

Description

-y, --yes, or --assume-yes

All Produces a “yes” response to any yes/no prompt in installation scripts.

-b, --compile, or --build

source Compiles a source package after retrieving it.

--no-upgrade install Causes apt-get to not upgrade a package if an older version is already installed.

If you use APT to automatically upgrade all packages on your system, you’re effectively giving control of your computer to the distribution main-tainer. Although Debian 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.

In Exercise 2.2, you’ll familiarize yourself with the Debian package system.

E X E R C I S E 2 . 2

Managing Debian Packages

To manage Debian packages, 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-1ubuntu1_amd64.deb, a shell that’s not installed by default on most systems, obtained using the -d option to apt-get on an Ubuntu 12.04 system. You must adjust the commands as necessary if you use another package, distribution, or architecture 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.

c02.indd 68

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

5. Type dpkg -L zsh to verify that the package isn’t currently installed. This command responds with a list of fi les associated with the package if it’s installed or with an error that reads Package `zsh’ is not installed if it’s not.

6. Type dpkg -I zsh_4.3.17-1ubuntu1_amd64.deb. (You’ll need to add a complete path to the package fi le if it’s not in your current directory.) The system should respond by dis-playing information about the package, such as the version number, dependencies, the name of the package maintainer, and a package description.

7. Type dpkg -i zsh_4.3.17-1ubuntu1_amd64.deb. The system should install the package and display a series of lines summarizing its actions as it does so.

8. Type dpkg -p zsh. The system should respond with information about the package similar to that displayed in step 6.

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 slightly, but you can issue most of the same commands you can use with bash or tcsh.

10. Type dpkg -P zsh. This command removes the package from the system, including confi guration fi les. It may produce a series of warnings about non-empty directories that it couldn’t remove. 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 because fi les will be missing after you remove the package.

11. Type exit to exit from zsh and return to your normal shell.

12. Type dpkg -L zsh. The system should respond with a Package `zsh’ is not installed error because you’ve just uninstalled it.

13. Type apt-get install zsh to install zsh using the APT system. Depending on your confi guration, the system may download the package from an Internet site or ask you to insert a CD-ROM. If it asks for a CD-ROM, insert it and press the Enter key. The system should install the package.

14. Type dpkg -p zsh. The system should respond with information about the package similar to that displayed in step 6 or 8.

15. Type dpkg -P zsh. This command removes the package from the system, as described in step 10.