Objective 5: Use 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. Most package versions are the same as that of the software they contain. The format of package versions varies from package to package, but most are numeric (major.minor.patchlevel).

A file extension

By default, all Debian packages end with .deb file extension.

Figure 4-1 illustrates a Debian package name.

The structure of a Debian GNU/Linux package name

Figure 4-1. The structure of a Debian GNU/Linux package name

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.

The dselect command offers an interactive menu that allows the administrator to select from a list of available packages and mark them for subsequent installation. The alien command allows the use of non-Debian packages, such as the Red Hat RPM format.

For complete information on Debian package management commands, see details in their respective manpages.


dpkg [options] action

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

The dpkg command maintains package information in /var/lib/dpkg. There are two files that are of particular interest:


The list of all available packages.


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

Do not overwrite a previously installed package of the same version.


Do 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 options
--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 backing up 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.

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) ...

Alternatively, 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:
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...)
Example 4

Use the dpkg -S command to find a package containing specific files. 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

Obtain package status information, such as 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 6

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

# dpkg -L apt | grep '^/usr/bin'
Example 7

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

# dpkg -l xdm
ii  xdm       X display manager
Example 8

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


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

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.


Simulate the steps in a package change, but do not actually change the system.


Automatically respond "yes" to all prompts, instead of prompting you for a response during package installation/removal.

Frequently used commands

Upgrade automatically to new versions of Debian Linux.


Install or upgrade one or more packages by name.


Remove specified packages.


Fetch a list of currently available packages. This is typically done before any changes are made to existing packages.


Upgrade a system's complete set of packages to current versions safely. This command is conservative and will not process upgrades that could cause a conflict or break an existing configuration; it also 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. The file should contain one or more lines that look something like this:

deb http://http.us.debian.org/debian stable main contrib non-free

Remove the elvis package using apt-get.

# apt-get remove elvis
Reading Package Lists... Done
Building Dependency Tree... Done
The following packages will be REMOVED:
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...)

In this example, the user is required to respond with y when prompted to continue. Using the -y option to apt-get would eliminate this interaction.



dselect is an interactive, menu-driven, frontend tool for dpkg and is usually invoked without parameters. The dselect command lets you 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, and generic .tar.gz files. rpm must also be installed on the system 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

Automatically install the output package and remove the converted package file.


Convert package to RPM format.


Convert package to a gzip tar archive.


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

alien -i package.rpm

Get LPI Linux Certification in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.