Debian Package Management

A quick overview of the package management tools of Debian (apt-get, aptitude and dpkg) with examples how to use them. Covers the common tasks: install, remove, examine, search


search for installed packages containing 'apache'

aptitude search apache | grep ^i

purge configuration files of removed packages

aptitude purge '~c'

show all available version of the named package 'nginx'

aptitude versions nginx


Search for packages containing the word bridge

apt-cache search bridge

Show the description of a package:

apt-cache show bridge-utils

Show dependencies of a package:

apt-cache depends fontconfig

Show reverse dependencies of a package (which packages depend on the given package)

apt-cache rdepends fontconfig


Install (security) updates:

apt-get update
apt-get --show-upgraded upgrade

This will update the apt repository and show which packages are to be updated

Upgrade a single package:

apt-get update
apt-get install --only-upgrade package

Downgrade a package to a specific version:

apt-get install pkg=version
apt-get install puppet-agent=1.9.3-1jessie

'Cherry pick' which package(s) to upgrade:

apt-get install --only-upgrade package1 package2

Force (re)install of a Package

apt-get --reinstall install package1

Update packages and install dependend new packages (if there are any):

apt-get dist-upgrade


The man page reads: finds packages that have no packages depending on them. The default operation is to search only within the libs and oldlibs sections to hunt down unused libraries.

deborphan | xargs dpkg --purge

This command line will purge libs found by deborpan.


Save package selections to file:

dpkg --get-selections '*' > ~/dpkg_packages

Restore selections:

dpkg --set-selections < ~/dpkg_packages
apt-get dselect-upgrade

Set package(s) on hold or to install:

echo "redis-server hold" | dpkg --set-selections
echo "redis-server install" | dpkg --set-selections

Determine which packages are set to hold:

dpkg --get-selections | grep hold

Install a package:

dpkg -i packagename
dpkg --install packagename

Reconfigure an already installed package:

dpkg-reconfigure packagename

Query .deb file

dpkg-deb --info foo.deb
dpkg-deb --contents foo.deb

List all files in a package:

dpkg -L packagename
dpkg --listfiles packagename

Query an (installed) package:

dpkg -s packagename
dpkg --status packagename

Remove a package, leaving the config files in place:

dpkg -r packagename
dpkg --remove packagename

Purge a package with ALL config files:

dpkg -P packagename
dpkg --purge packagename

Search package to which a given file belongs:

dpkg -S pattern
dpkg --search pattern

Check architecture (amd64, i386, …):

dpkg --print-architecture

List details about currently installed packages:

dpkg --list puppet*

Do database sanity and consistency checks:

dpkg -C
dpkg --audit

Install a downloaded deb-package and its dependencies

Ever downloaded a deb-package and found it awkward to install because of failed dependencies?
Here's the two-step solution:

# try to install the downloaded package:
dpkg -i package.deb
# ... dpkg complains because failed dependencies ...
apt-get -f install
# -f means fix-broken and tries to install all the missing packages

Signing Keys

  • There are no public key available for the following key IDs …


 apt-get update && apt-get install debian-archive-keyring && apt-get update



Repositories are grouped into components:

Debian components:

  • main
  • contrib
  • non-free

Ubuntu components:

  • main
  • restricted
  • universe
  • multiverse


Things have changed since Wheezy was released (to the better).

If you need Backports for Squeeze see

For Wheezy and newer it's straight forward:

echo "deb wheezy-backports main" > /etc/apt/sources.list.d/backports.list
apt-get update

Install your favourite backported package as follows:

aptitude -t wheezy-backports install “package”

A useful tool to investigate which packages are upgradable is apt-show-versions:

~# apt-show-versions -a --package=puppet
puppet 2.6.2-5+squeeze4 install ok installed
puppet 2.6.2-5+squeeze1 squeeze 
puppet 2.6.2-5+squeeze4 squeeze 
puppet 2.7.6-1~bpo60+1  squeeze-backports
puppet/squeeze uptodate 2.6.2-5+squeeze4

~# apt-show-versions --upgradeable
mutt/etch upgradeable from 1.5.13-1.1etch1 to 1.5.18-2~bpo40+1

Debian Archive is a repository for old Debian releases.

If you are using APT the relevant sources.list entries are like:

deb $RELEASE main contrib

for example:

deb etch main contrib
debian/packagemanagement.txt · Last modified: 2019-05 by tb
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready