Commands for the package management system in Ubuntu/Debian

The command-line tools for apt/dpkg are surprisingly unintuitive, and I could not find any useful yet concise guide, so here is my attempt. (I dare to put Debian in the title, since all documentation indicates that Ubuntu's and Debian's package management systems are the same, but have not tested these commands on Debian.)

First, some background. dpkg is the package management system in Debian and Ubuntu. It operates on .deb package files. APT is a higher-level tool (or more precisely suite of tools) capable of getting packages from remote servers along with other magic involving dependencies and such.

Now, the commands.

  • Install a package.
    apt-get install 
  • Find a package you might want to install.
    apt-cache search 
  • View detailed information about a particular package (whether installed or not).
    apt-cache show 
  • View list of installed packages.
    dpkg -l
  • View concise information about a particular package (whether installed or not).
    dpkg -l 
    See https://lists.ubuntu.com/archives/kubuntu-users/2006-July/006993.html for a good summary of the status codes in the dpkg -l output.
  • View detailed information about a particular installed package.
    dpkg -s 
  • List the files installed by a package (that has been installed).
    dpkg -L 
  • Find the package that a file belongs to.
    dpkg -S