Debian Package Management

by Peter Jay Salzman



dpkg

The dpkg utility is a command-line based program that's mainly used in 2 cases:
  1. Operations on a Debian package sitting on your local hard drive, like installing it.
  2. Operations on packages already installed on your system, like listing the files a package placed on your hard drive and printing information about an installed package.

Useful dpkg Commands

The following conventions are used:
Installation and Removal
dpkg -i <pkg.deb> dpkg --install <pkg.deb> Install the package <pkg>, and back up its previous version.
dpkg -r <pkg-name> dpkg --remove <pkg-name> Remove package <pkg> but leave the configuration files in place.
dpkg -P <pkg-name> dpkg --purge <pkg-name> Purge package <pkg>, including the configuration files.

Informational
dpkg -S <file> dpkg --search <file> Lists what package the file <file> belongs to.
dpkg -l <string> dpkg --list <string> List all packages matching the regular expression <string>.
dpkg -L <pkg-name> dpkg --listfiles <pkg-name> List all the files provided by the installed package <pkg-name>.
dpkg -c <pkg.deb> dpkg --contents <pkg.deb> List the files provided by the package file <pkg.deb>.
dpkg -p <pkg-name> dpkg --print-avail <pkg-name> List detailed information about the package <pkg-name>.
dpkg -I <pkg.deb> dpkg --info <pkg.deb> List detailed information about the package file <pkg.deb>.

Configuration And Status
dpkg -s <pkg-name> Report status on the packkage <pkg-name>.
dpkg -C Report all half installed packages.
dpkg --configure <pkg-name> Configure the package <pkg-name>.
dpkg --configure --pending Configure all package which need configuring.

Miscellaneous
dpkg -x <pkg.deb> <dir> Extract a package file into directory <dir>.
dpkg -X <pkg.deb> <dir> Lists files as it extracts them, like tar's v option.

Sometimes dpkg won't install or delete a package. There could be a whole host of reasons, including package dependencies or the package was compiled for a different architecture. You can always force the issue. See dpkg --force-help for details.

dpkg understands shell globbing type metacharacters (such as the wildcard *). For example, to list all Tcl packages, use dpkg -l "tcl*". You need to use quotes to protect the asterisk from being interpreted by the shell (which happens before the shell passes -l "tcl*" to dpkg). I suppose you could do something like dpkg -r "*", but frankly, I'm too scared to even try.

Package Information Via dpkg

When you list packages using the -l option, the output will look something like this:
Desired=Unknown/Install/Remove/Purge
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err:
uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
pn  lynx           2.8.2-6        Text-mode WWW Browser
ii  lynx-ssl       <none>      (no description available)
Notice there are 3 columns underneath the + signs (the 3rd column is empty).
  1. The leftmost column gives the desired status of the package.
  2. The middle column gives the actual status of the package.
  3. The rightmost column gives any errors that exist in the package's status.
The status letters that I know about are:

Prev: Basic Principles Up: Peter's Debian Notes Next: apt

Mail corrections, suggestions and kudos to: p@dirac.org