Linux DevCenter    
 Published on Linux DevCenter (http://www.linuxdevcenter.com/)
 http://linux.oreilly.com/news/lpilinux_0501.html
 See this if you're having trouble printing code examples


Package Management on LPI Exam 102

by Jeff Dean
05/24/2001

A side effect of the simplification was the inclusion of the important topic of package management on Exam 102. Both the Red Hat and Debian package management schemes were retained from their respective distribution-specific then in development and added to the new Exam 102. Due to the significance of package management in Linux administration, it is tested thoroughly on Exam 102. You can use this to your advantage by doing some package management homework prior to taking Exam 102.

Debian Package Management

The Debian package management system is a versatile and automated suite of tools used to acquire and manage software packages for Debian Linux. The system automatically handles many of the management details associated with interdependent software running on your system.

Debian Package Management Overview

Each Debian package contains program and configuration files, documentation, and noted dependencies on other packages. The names of Debian packages have three common elements, including:

Managing Debian Packages

The original Debian package management tool is dpkg, which operates directly on .deb package files and can be used to automate the installation and maintenance of software packages. The alternative apt-get tool operates using package names, obtaining them from a predefined source (such as CD-ROMs, FTP sites, etc.). Both tools work from the command line.

dpkg

dpkg [Options] action

The Debian package manager command, dpkg, consists of an action that specifies a major mode of operation and zero or more Options, which modify the action's behavior.

The dpkg command maintains package information in /var/lib/dpkg. Two files there of particular interest are:

These files are modified by dpkg, dselect, and apt-get, and it is unlikely that they will ever need to be edited.

Frequently Used Options

Frequently Used Actions

apt-get

apt-get [Options] [Command] [package_name ...]

The apt-get command is part of the Advanced Package Tool (APT) management system. It does not work directly with .deb files like dpkg, but uses package names instead. apt-get maintains a database of package information that enables the tool to automatically upgrade packages and their dependencies as new package releases become available.

Frequently Used Options

Frequently Used Commands

Additional commands and options are available. See the apt-get manpage for more information.

apt-get uses /etc/apt/sources.list to determine where packages should be obtained. This file is not in the Objectives for Exam 102.

Some other debian package management commands aren't prominent on the exams but are of course important:

Related Reading

LPI Linux Certification in a Nutshell

LPI Linux Certification in a Nutshell
Covers General Linux Exams 101 and 102
By Jeff Dean

Table of Contents
Index
Sample Chapter

Read Online--Safari Search this book on Safari:
 

Code Fragments only

Frequently Used Options

dselect, apt-get, and alien are important parts of Debian package management, but detailed knowledge of dpkg is of primary importance for Exam 102.

Example 1

Install a package using dpkg -i with the name of an available package file:

# dpkg -i ./hdparm_3.3-3.deb
(Reading database ... 54816 files and directories
   currently installed.)
Preparing to replace hdparm 3.3-3 (using hdparm_3.3-3.deb)
Unpacking replacement hdparm ...
Setting up hdparm (3.3-3) ...

Or use apt-get install with the name of the package. In this case, the package comes from the location or locations configured in /etc/apt/sources.list. For this example, the location is http://http.us.debian.org:

# apt-get install elvis
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
   libncurses4 xlib6g
The following NEW packages will be installed:
   elvis
2 packages upgraded, 1 newly installed, 0 to remove
   and 376 not upgraded.
Need to get 1678kB of archives. After unpacking 2544kB
   will be used.
Do you want to continue? [Y/n] y
Get:1 http://http.us.debian.org stable/main
   libncurses4 4.2-9 [180kB]
Get:2 http://http.us.debian.org stable/main
   xlib6g 3.3.6-11 [993kB]
Get:3 http://http.us.debian.org stable/main
   elvis 2.1.4-1 [505kB]
Fetched 1678kB in 4m11s (6663B/s)
(Reading database ... 54730 files and directories
   currently installed.)
Preparing to replace libncurses4 4.2-3 (using
   .../libncurses4_4.2-9_i386.deb) ...
Unpacking replacement libncurses4 ...
(installation continues...)

Example 2

Upgrading a package is no different from installing one. However, you should use the -G option when upgrading with dpkg to ensure that the installation won't proceed if a newer version of the same package is already installed.

Example 3

Use dpkg -r or dpkg --purge to remove a package:

# dpkg --purge elvis
(Reading database ... 54816 files and directories
   currently installed.)
Removing elvis ...
(purge continues...)

Similarly, using apt-get:

# apt-get remove elvis
Reading Package Lists... Done
Building Dependency Tree... Done
The following packages will be REMOVED:
   elvis
0 packages upgraded, 0 newly installed, 1 to remove
   and 376 not upgraded.
Need to get 0B of archives. After unpacking 1363kB
   will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 54816 files and directories
   currently installed.)
Removing elvis ...
(removal continues...)

If you compare the output of these two commands, it becomes apparent that apt-get is calling dpkg to act on packages.

Example 4

To find a package containing specific files use the dpkg -S command. In this example, apt-get is contained in the apt package:

# dpkg -S apt-get
apt: /usr/share/man/man8/apt-get.8.gz
apt: /usr/bin/apt-get

Example 5

Use dselect to select packages. Or if you know which packages you need, use apt-get to fetch and install them.

Example 6

Obtain package status information like version, content, dependencies, integrity, and installation status using dpkg -s:

# dpkg -s apt
Package: apt
Status: install ok installed
Priority: optional
Section: admin
Installed-Size: 1388
(listing continues...)

Example 7

List the files in a package using dpkg -L and process the output using grep or less:

# dpkg -L apt | grep '^/usr/bin'
/usr/bin
/usr/bin/apt-cache
/usr/bin/apt-cdrom
/usr/bin/apt-config
/usr/bin/apt-get

Example 8

List the installed packages using dpkg -l; if you don't specify a pattern, all packages will be listed:

# dpkg -l xdm
ii xdm 3.3.2.3a-11 X display manager

Example 9

Use dpkg -S to determine the package from which a particular file was installed with the filename:

# dpkg -S /usr/bin/nl
textutils: /usr/bin/nl

Example 10

Install a non-Debian package on Debian system using alien with the -i option:

alien -i package.rpm

Red Hat Package Manager (RPM)

The Red Hat Package Manager is among the most popular methods for the distribution of software for Linux and is installed by default on many distributions. It automatically handles many of the management details associated with interdependent software running on your system.

RPM Overview

RPM automates the installation and maintenance of software packages. Built into each package are program files, configuration files, documentation, and dependencies on other packages. Package files are manipulated using the rpm command, which maintains a database of all installed packages and their files. Information from new packages is added to this database, and it's consulted on a file-by-file basis for dependencies when packages are removed, queried, and installed.

As with Debian packages, RPM filenames have three common elements:

An RPM filename is constructed by tying these elements together in one long string. There are three uses for hyphens in RPM filenames. They appear as word separators in package names, as a delimiter between names and versions, and as part of the version. This may be confusing at first, but the version is usually obvious, making the use of hyphens unambiguous.

Running RPM

The rpm command provides for the installation, removal, upgrade, verification, and other management of RPM packages and has a bewildering array of options. Some are of the traditional single-letter style while others are the --option variety. In most cases both styles exist and are interchangeable. At first glance, configuring rpm may appear to be a bit daunting. However, its operation is segmented into modes, which are enabled using one (and only one) of the mode options. Within a mode, additional mode-specific options become available to modify the behavior of rpm. The major modes of rpm and some of the most frequently used mode-specific options follow. For complete information on how to use and manage RPM packages, see the rpm manpage or the synopsis offered by rpm --help.

rpm -i (also rpm --install),
rpm -U (also rpm --upgrade)
rpm -e (also --uninstall)
rpm -q (also --query)
rpm -V

Install/Upgrade mode

The install mode (rpm -i) is used to install new packages. A variant of install mode is the upgrade mode (rpm -U), where an installed package is upgraded to a more recent version.

Frequently Used Install- and Upgrade-Mode Options

Uninstall Mode

This mode is used to remove installed packages from the system. By default, rpm will uninstall a package only if no other packages are dependent on it.

Frequently Used Uninstall-Mode Options

Frequently Used Query-Mode Package Selection Options

Frequently Used Query-Mode Information Selection Options

Frequently Used Verify-Mode Options

There are also modes for building, rebuilding, signing, and checking the signature of RPM files, however, those are beyond the scope of the LPI Level 1 exams.

Example 1

To install a new package, simply use the rpm -i command with the name of a package file. If the new package depends upon another package, the install will fail, like this:

# rpm -iv
netscape-communicator-4.72-3.i386.rpm error: failed dependencies:
netscape-common = 4.72 is needed by netscape-communicator-4.72-3

To correct the problem, the dependency must first be satisfied. In this example, netscape-communicator is dependent on netscape-common, which is installed first:

# rpm -iv netscape-common-4.72-3.i386.rpm netscape-common
# rpm -iv netscape-communicator-4.72-3.i386.rpm netscape-communicator

Example 2

Upgrading an existing package to a newer version can be done with the -U option. Upgrade mode is really a special case of the install mode, where existing packages can be superseded by newer versions. Using -U, a package can be installed even if it doesn't already exist, in which case it behaves just like -i:

# rpm -U netscape-common-4.72-3.i386.rpm

Example 3

Package removal is the opposite of installation and has the same dependency constraints:

# rpm -e netscape-common error: removing these packages
would break dependencies: netscape-common = 4.72 is needed 
by netscape-communicator-4.72-3

Example 4

To determine the version of the software contained in an RPM file, use the query and package information options:

# rpm -qpi xv-3.10a-13.i386.rpm | grep Version
Version : 3.10a
Vendor: Red Hat Software

For installed packages, omit the -p option and specify a package name instead of a package filename:

# rpm -qi kernel-source | grep Version
Version : 2.2.5
Vendor: Red Hat Software

Example 5

Enter query mode and list the files contained in a package:

# rpm -qlp gnucash-1.3.0-1.i386.rpm
/usr/bin/gnc-prices
/usr/bin/gnucash
/usr/bin/gnucash.gnome
/usr/doc/gnucash
/usr/doc/gnucash/CHANGES
(...output continues ...)

For an installed package, enter query mode and use the -l option along with the package name:

# rpm -ql kernel-source
/usr/src/linux-2.2.5/COPYING /usr/src/linux-2.2.5/CREDITS
/usr/src/linux-2.2.5/Documentation
/usr/src/linux-2.2.5/Documentation/00-INDEX
/usr/src/linux-2.2.5/Documentation/ARM-README
(...output continues...)

Example 6

List the documentation files in a package:

# rpm -qd
at /usr/doc/at-3.1.7/ChangeLog
/usr/doc/at-3.1.7/Copyright
/usr/doc/at-3.1.7/Problems
/usr/doc/at-3.1.7/README
/usr/doc/at-3.1.7/timespec
/usr/man/man1/at.1
/usr/man/man1/atq.1
/usr/man/man1/atrm.1
/usr/man/man1/batch.1
/usr/man/man8/atd.8
/usr/man/man8/atrun.8

Use -p for package filenames.

Example 7

List configuration files or scripts in a package:

# rpm -qc at /etc/at.deny
/etc/rc.d/init.d/atd

Example 8

Determine the package from which a particular file was installed. Of course, not all files originate from packages:

# rpm -qf /etc/issue
file /etc/issue is not owned by any package

Those that are package members will look like this:

# rpm -qf /etc/aliases
sendmail-8.9.3-10

Example 9

List the packages that have been installed on the system (all or a subset):

# rpm -qa
(... hundreds of packages are listed ...)

To search for a subset with kernel in the name, pipe the previous command to grep:

# rpm -qa | grep kernel
kernel-headers-2.2.5-15
kernel-2.2.5-15
kernel-pcmcia-cs-2.2.5-15
kernel-smp-2.2.5-15
kernel-source-2.2.5-15
kernelcfg-0.5-5
kernel-ibcs-2.2.5-15
kernel-doc-2.2.5-15

Jeffrey Dean is a freelance author, editor, and consultant in Philadelphia, Pennsylvania. He has professional experience in IT management, training delivery, and system administration of Linux, Solaris, VMS, AS/400, and Windows NT/2000. Jeffrey holds an undergraduate degree in electrical engineering from the University of Pittsburgh and a master's in engineering with emphasis in computer design from Penn State. He holds the Linux Professional Institute Level 1 (LPIC-1) and Red Hat Certified Engineer (RHCE) certifications.


O'Reilly & Associates will soon release (May 2001) LPI Linux Certification in a Nutshell.

Copyright © 2007 O'Reilly Media, Inc.