Purpose: Debian has a very powerful package management system called APT. Learning some useful commands can really unleash the true power and usefulness of this package management system. From time to time I will add commands and other tips and tricks that will be helpful to solve some issues and get work done faster. The idea is to make this post a COMPREHENSIVE command guide for APT package management.

Note: For most of the examples, I have used “traceroute” as an example package wherever possible. In some scenarios I have used other packages for the example since traceroute was not suitable for those.

APT-GET Commands

  • To install a package. For example, let say you would like to install traceroute package:

#apt-get install traceroute

  • To install a package’s source files. For example, let say you would like to download “traceroute” package’s source:

# apt-get source traceroute

  • To install dependencies of a package for building the package from it’s source. For example, before you start building a binary package (traceroute) from it’s source, you need to install the dependencies that are required to build the package from it’s source:

# apt-get build-dep traceroute

  • To build a package from it’s source:

# apt-get source traceroute
# cd traceroute-VERSION
# debuild -uc -us
# cd ..

  • To fix a system with incorrect/broken dependencies. Also useful if the apt-get was stopped unexpectedly due to crash or power failure:

# apt-get -f install

DPKG-based Commands

  • To reconfigure any package that is unpacked but not yet configured or half-configured state. This can be used along with “apt-get -f install”. Also useful in case of unexpected shutdown while upgrading the system.

# apt-get -f install
# dpkg --configure -a

  • To remove a package (this does not remove the configuration files of the package):

# dpkg --remove traceroute

  • To remove a package (and its configuration files):

# dpkg --purge traceroute

  • To reconfigure a package. For example suppose you want to select a different settings for your X server:

# dpkg-reconfigure xserver-xorg

  • To identify the package name that produced a particular file. For example, “I would like to know which Debian package produced the file ‘lft.db’:

# dpkg -S lft.db
# dpkg --search lft.db


traceroute: /usr/bin/lft.db
traceroute: /usr/share/man/man8/lft.db.8.gz

  • To list all the files installed a particular package:

# dpkg --listfiles traceroute

  • To list all the packages installed on the system along with their state, name, version and a description:

# dpkg --list

  • To list all the packages installed on the system (only names):

# dpkg --get-selections

  • To get detailed information about a downloaded package (deb file):

# dpkg --info traceroute_2.0.11-2_i386.deb


new debian package, version 2.0.
size 47346 bytes: control archive= 1482 bytes.
904 bytes,    20 lines      control
876 bytes,    14 lines      md5sums
815 bytes,    35 lines   *  postinst             #!/bin/sh
421 bytes,    27 lines   *  prerm                #!/bin/sh
Package: traceroute
Version: 2.0.11-2
Architecture: i386
Maintainer: Daniel Baumann <daniel@debian.org>
Installed-Size: 168
Depends: libc6 (>= 2.7-1)
Conflicts: tcptraceroute (<< 1.5beta6-2.1), traceproto (<< 1.1.2beta1-3), traceroute-nanog (<< 6.4.2-1)
Section: net
Priority: important
Homepage: http://traceroute.sourceforge.net/
Description: Traces the route taken by packets over an IPv4/IPv6 network
The traceroute utility displays the route used by IP packets on their way to a
specified network (or Internet) host. Traceroute displays the IP number and
host name (if possible) of the machines along the route taken by the packets.
Traceroute is used as a network debugging tool. If you’re having network
connectivity problems, traceroute will show you where the trouble is coming
from along the route.
Install traceroute if you need a tool for diagnosing network connectivity

  • To extract the contents of a downloaded deb package:

# ar -x traceroute_2.0.11-2_i386.deb


control.tar.gz    data.tar.gz  debian-binary  traceroute_2.0.11-2_i386.deb

APT-CACHE Commands

  • To perform a full-text search on a package’s name, description, etc:

# apt-cache search traceroute

  • To print detailed information of a package:

# apt-cache show traceroute

  • To print a  list of packages a given package (traceroute) depends on. For example, show me all the packages on which traceroute depends:

# apt-cache depends traceroute


Depends: libc6
Conflicts: tcptraceroute
Conflicts: <traceproto>
Conflicts: traceroute-nanog

  • To print a list of packages that are dependent on a particular package. For example, show me all the packages that are dependent on “traceroute” package:

# apt-cache rdepends traceroute


Reverse Depends:

  • To print detailed information of the versions available for a package and the packages that reverse-depends on it. For example, show me all the packages which depends on traceroute:

# apt-cache showpkg traceroute

Troubleshooting package installation process

  • To troubleshoot error messages like the following:

Unpacking dictionaries-common (from …/dictionaries-common_0.98.12_all.deb) …
dpkg-divert: cannot open diversions: No such file or directory
dpkg: error processing /var/cache/apt/archives/dictionaries-common_0.98.12_all.deb (–unpack):
subprocess pre-installation script returned error exit status 2
Selecting previously deselected package aspell.
Unpacking aspell (from …/aspell_0.60.6-1_i386.deb) …
Processing triggers for man-db …
Errors were encountered while processing:
E: Sub-process /usr/bin/dpkg returned an error code (1)
debian-486:/var/lib/dpkg# ls

# touch /var/lib/dpkg/diversions

  • To troubleshoot error messages like following:

Errors were encountered while processing:
/var/cache/apt/archives/acpid_ 1.0.8-7.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

Try following commands one by one:

# apt-get -f install
# apt-get upgrade
# apt-get dist-upgrade

# dpkg --configure -a
# apt-get -f install

# cd /var/lib/dpkg/info
# rm -rf acpid*
# apt-get install acpid

# cd /var/lib/apt/lists
# rm *
# apt-get update
# apt-get install acpid

# cd /var/cache/apt/archives
# rm acpid_ 1.0.8-7.deb
# apt-get install acpid

Be Sociable, Share!