Package Management on LPI Exam 102
by Jeff Dean05/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:
Package name: A Debian package name is short and descriptive. When multiple words are used in the name, they are separated by hyphens. Typical names include binutils, kernel-source, and telnet.
-
Version number: Each package has a version number. Most package versions are the same as that of the software they contain, thus the format of package versions varies from package to package. Most are numeric, with major, patch, and release numbers, but other information may appear as well. Typical versions are 0.6.7-7; 0.96a-14; 6.05; 80b2-8; and 2.0.7.19981211. The version is separated from the package name with an underscore.
-
A file extension: By default, all Debian packages end with .deb file extension.
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:
- available: The list of all available packages
- status: Contains package attributes, such as whether it is installed or marked for removal
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
-E: Using this option, dpkg will not overwrite a previously installed package of the same version.
-G: Using this option, dpkg will not overwrite a previously installed package with an older version of that same package.
-R: (also --recursive) Recursively process package files in specified subdirectories. Works with -i, --install, --unpack, and so on.
Frequently Used Actions
--configure package: Configure an unpacked package. This involves setup of configuration files.
-i package_file (also --install package_file): Install the package contained in package_file. This involves backup of old files, unpacking and installation of new files, and configuration.
-l [pattern] (also --list [pattern]): Display information for installed package names that match pattern.
-L package (also --listfiles package): List files installed from package.
--print-avail package: Display details found in /var/lib/dpkg/available about package.
--purge package: Remove everything for package.
-r package (also --remove package): Remove everything except configuration files for package.
-s package (also --status package): Report the status of package.
-S search_pattern (also --search search_pattern): Search for a filename matching search_pattern from installed packages.
--unpack package_file: Unpack package_file, but don't install the package it contains.
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
-d: Download files, but do not install. This is useful when you wish to get a large number of package files but delay their installation to prevent installation errors from stopping the download process.
-s: Simulate the steps in a package change, but do not actually change the system.
-y: Automatically respond "yes" to all prompts, instead of prompting you for a response during package installation/removal.
Frequently Used Commands
dist-upgrade: This command is used to automatically upgrade to new versions of Debian Linux.
install: The install command is used to install or upgrade one or more packages by name
.remove: This command is used to remove the specified packages.
update: Running apt-get update fetches a list of currently available packages. This is typically done before any changes are made to existing packages.
upgrade: The upgrade command is used to safely upgrade a system's complete set of packages to current versions. It is conservative and will not process upgrades that could cause a conflict or break an existing configuration; it will not remove packages.
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 |
dselect: dselect is an interactive, menu-driven front-end tool for dpkg and is usually invoked without parameters. The dselect command lets you to interactively manage packages by selecting them for installation, removal, configuration, and so forth. Selections are made from a locally stored list of available packages, which may be updated while running dselect. Package actions initiated by dselect are carried out using dpkg.
alien [--to-deb] [--patch=patchfile] [Options] file: Convert to or install a non-Debian (or "alien") package. Supported package types include Red Hat .rpm, Stampede .slp, Slackware .tgz, as well as generic .tar.gz files. rpm must also be installed on the system in order to convert an RPM package into a .deb package. The alien command produces an output package in Debian format by default after conversion.
Frequently Used Options
- -i: Automatically install the output package and remove the converted package file.
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:
Name: An RPM package name is short and descriptive. If multiple words are used, they are separated by hyphens (not underscores, as you might expect). Typical names include binutils, caching-nameserver, cvs, gmc, kernel-source, and telnet.
Version: Each package has a version. Most package versions are the same as that of the software they contain, thus the format of package versions varies from package to package. Most are numeric, with major, patch, and release numbers, but other information may appear as well. Typical versions are 3.0beta5-7, 1.05a-4, 2.7-5, 1.10.5-2, 1.1.1pre2-2, 1.14r4-4, 6.5.2-free3-rsaref, and 0.9_alpha3-6. The version is separated from the name by a hyphen.
Architecture: Packages containing binary (compiled) files are by their nature specific to a particular type of system. For PCs, the RPM architecture designation is i386, meaning the Intel 80386 and subsequent line of microprocessors and compatibles. For Sun and Sun-compatible processors, the architecture is sparc. The architecture is separated from the version by a dot.
A .rpm extension: All RPM files end with .rpm extension by default.
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
--force: This option allows the replacement of existing packages and of files from previously installed packages; for upgrades, it allows the replacement of a newer package with an older one.
-h (also --hash): This option adds a string of 50 hash marks (#) during installation as a sort of progress indicator.
--nodeps: rpm will skip dependency checking with this option enabled. This allows you to install a package without regard to dependencies.
--test: This option will run through all the motions except for actually writing files; it's useful to verify that a package will install correctly prior to making the attempt. Note that verbose and hash options cannot be used with --test, but -vv can.
-v: This option sets verbose mode.
-vv: This sets really verbose mode. The manpage describes this as "print lots of ugly debugging information."
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
--nodeps: rpm will skip dependency checking with this option enabled.
--test: This option will run through all the motions except for actually uninstalling things; it's useful to verify that a package can be uninstalled correctly without breaking other dependencies prior to making the attempt. Note that verbose and hash options cannot be used with --test, but -vv can.
Query mode: Installed packages and raw package files can be queried using the rpm -q command. Query-mode options exist for package and information selection.
Frequently Used Query-Mode Package Selection Options
-
-a (also --all): Display a list of all packages installed on the system. This is particularly useful when piped to grep when you're not sure of the name of a package or when you want to look for packages that share a common attribute.
-f filename (also --file): Display the package that contains a --> --particular file.
-p package_filename: Query a package file. Most useful with -i, --> -- described next.
Frequently Used Query-Mode Information Selection Options
-c (also --configfiles): List only configuration files.
-d (also --docfiles): List only documentation files.
-i package: Not to be confused with the install mode. Display information about an installed package or, when combined with -p, about a package file. In the latter case, package is a filename.
-l package (also --list): List all of the files contained in package. When used with -p, the package is a filename.
-R (also --requires): List packages on which this package depends. Verify mode Files from installed packages can be compared against their expected configuration from the RPM database using rpm -V.
Frequently Used Verify-Mode Options
- --nofiles: Ignores missing files.
- --nomd5: Ignores MD5 checksum errors.
- --nopgp: Ignores PGP checking errors.
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.
Sample Chapter 4, Linux Installation and Package Management, is available free online.
You can also look at the Table of Contents, the Index, and the Full Description of the book.
For more information, or to order the book, click here.