102.4 Debian Package Management edit
Candidates should be able to perform package management using the Debian package manager.
Key Knowledge Areas
- Install, upgrade and uninstall Debian binary packages.
- Find packages containing specific files or libraries which may or may not be installed.
- Obtain package information like version, content, dependencies, package integrity and installation status (whether or not the package is installed).
Most Linux distributions manage software using some form of package management to perform tasks such as installations, updates and queries. There are two main package management system in use today and what your distribution uses will depend on its heritage. Most distributions derived from Redhat use the rpm package manager, while those that are derived from Debian use the dpkg manager.
Debian Package Management
Systems using Debian based variants of Linux use the Debian Package Management system. The Debian system is more rigorous and configurable than the rpm system and is used by Debian derivatives such as Ubuntu. Under Debian system's packages are managed with 'dpkg' but you may be more familiar with dpkg management tools such as “apt” and “aptitude”.
Package Naming edit
Debian package names are formed as follows:
The release number indicates which Debian release of the version of the software the package contains, while the architecture name specifies the computer architecture (i386, sparc, all). So the above deb package is for xchat version 2.8.6-4ubuntu5 for the AMD64 architecture.
The dpkg command is controlled via command line parameters, which consist of an action and zero or more options. The action parameter tells dpkg what to do and options control the behaviour of the action in some way.
dpkg maintains some usable information about available packages. The information is divided in three classes: states, selection states and flags.
|The package is unpacked and configured OK.
|The installation of the package has been started, but not completed for some reason.
|The package is not installed on your system.
|The package is unpacked, but not configured.
|The package is unpacked and configuration has been started, but not yet completed for some reason.
|Only the configuration files of the package exist on the system.
|A package marked to be on hold is not handled by dpkg, unless forced to do that with option --force-hold.
|A package marked reinst-required is broken and requires reinstallation. These packages cannot be removed, unless forced with option --force-reinstreq.
The heart of dpkg operation is the command line parameters specifying the action which should be performed. While there are a large number of these, the following table summarises the main actions you are likely to require on any regular basis.
|Prints a list of the packages installed on the system, or matching a pattern if any is given. The first three characters on each line show the state, selection state, and flags of the package
|Shows the status and information about particular installed package(s)
|Show information about a package in a .deb file
|List the files included in a package
|Show the package which includes the file specified
|Install (or upgrade) and configure a package from a .deb file
|Unpack (only) a package in a .deb file
|Configure an unpacked package. With -a (or --pending) configures all packages requiring configuration
|Remove a package (but leave its configuration files)
|Purge – remove a package along with its configuration files
|Get a list of package selections from a system (to stdout)
|Set the list of package selections for a system (from stdin)
All options can be specified both on the command line and in the dpkg configuration file /etc/dpkg/dpkg.cfg. Each line in the configuration file is either an option (exactly the same as the command line option but without leading dashes) or a comment (if it starts with a #).
|Forces dpkg to perform an action which it would normally not take (for example, to ignore dependency information - --force-depends, or to downgrade a package with –force-downgrade)
|Refuse to do something which dpkg would normally automatically do
|Ignore dependency checking for a package
|Show what dpkg would do, but don't do it (also: --simulate)
|Recurse through directories (using with -i or --unpack)
dpkg uses a number of files in its operation, including /etc/dpkg/dpkg.cfg which contains default configuration settings.
Lists of available packages along with their statuses are held in the files
/var/lib/dpkg/available and /var/lib/dpkg/status.
A .deb file, along with the files making up a packages programs, libraries and configuration, will also include a number of control files which allow the execution of scripts before and after installation and removal, along with lists of files and configuration files. These can be found in the /var/lib/dpkg/info directory once the packages are installed.
Use of dpkg
To install a package from a .deb file, you could use dpkg as follows:
# dpkg –i hello_2.1.1-4_i386.deb OR
# dpkg --unpack hello_2.1.1-4_i386.deb
# dpkg --configure hello
To remove the hello package along with its configuration, you could use:
# dpkg –P hello
# dpkg –r hello
would remove only the package, leaving its configuration files installed.
The get a list of all the packages installed on the system, use the command:
# dpkg –l
Note that when dealing with a package file, the filename is given, while when dealing with an installed package, only the package name is given.
The dpkg tool is fine for installing individual packages with no dependencies, but when installing a number of packages which may have dependencies, the APT tool is generally used instead.
APT is one of the strengths of dpkg, and provides an easy way of installing and updating a system. It is controlled by two files:
|Contains general configuration options for APT, such as which release of Debian to install, whether/which proxy settings to use, etc
|Lists sources of Debian files, which may be on CDs, or on the network
In general, to use APT you must first configure the sources it is to used. The main configuration file for apt is the /etc/apt/source.list file. This defines the repositories apt should use for installing new software or for updating existing applications. Below is an excerpt from an Ubuntu /etc/apt/sources.list file.
deb http://archive.ubuntu.com/ubuntu lucid main restricted
deb-src http://archive.ubuntu.com/ubuntu lucid main restricted
deb http://archive.ubuntu.com/ubuntu lucid-updates main restricted
deb-src http://archive.ubuntu.com/ubuntu lucid-updates main restricted
The type of archive can be either deb for binary packages or deb-src for source files. The rest of the line define repository location such by providing the url at which the repository can be found, and details needed to find the specific repository at the url location.
Once APT knows where the Debian packages are located, two command line tools are used for package management: apt-cache and apt-get.
apt-cache allows manipulation of the APT package cache (which is stored in files in /var/cache/apt). An action normally follows apt-cache on the command line, and common options include:
|Search all the available package descriptions for the string given, and print a short description of the matching package
|Shows a full description of the package specified
While apt-cache is useful for finding out information about available packages, apt-get allows updating of package information, retrieval, installation and removal of packages, and even upgrading of an entire Debian distribution. apt-get expects an action to be provided on the command line, and the most common are listed below:
|Update the list of packages from the sources in /etc/apt/sources.list
|Install the package(s) specified, along with any dependencies
|Upgrade any packages which have newer versions available
|Upgrade entire distribution to the latest release (best to read the release notes first!)
|Remove the package(s) specified
Use of APT
One use of APT is for updating the system (for example if security-related updates have become available). This is normally done using the two commands:
# apt-get update
# apt-get upgrade
The other main use of APT is to install required packages. This normally involves the following commands:
apt-get update #update list of packages
apt-cache search frob #find packages relating to frobbing
apt-cache show frobnicate #show information regarding a particular package
apt-get install frobnicate #install frobnicate package and its dependencies
The Alien Tool edit
The alien tool will change Debian packages into RedHat ones and vice versa. One can download it at: http://kitenet.net/programs/
Convert a debian package to an rpm:
#alien --to-rpm package.deb
Convert an rpm package to debian:
# alien --to-debian package.rpm
Aptitude is another text based front-end to the Debian package management system. Much like apt, aptitude can be used to install, remove and update software on Debian machines. Below is a list of commonly used parameters with aptitude:
- aptitude update – update the list of available packages.
- aptitude install – will install new software ,
- aptitude reinstall – will reinstall an existing package
- aptitude remove – will remove an existing package
- aptitude purge – will remove a package and its associated configuration files
- aptitude search – will allow you to search the list of available packages.
Used files, terms and utilities:* /etc/apt/sources.list