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

aptitude

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

apt-cache

Search for packages containing the word bridge

apt-cache search bridge

Show the description of a package:

apt-cache show bridge-utils

apt-get

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

deborphan

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.

dpkg

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
echoe "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

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 …

Solution:

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

Repositories

Components

Repositories are grouped into components:

Debian components:

  • main
  • contrib
  • non-free

Ubuntu components:

  • main
  • restricted
  • universe
  • multiverse

Backports

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

If you need Backports for Squeeze see http://backports.debian.org/Instructions/

For Wheezy and newer it's straight forward:

echo "deb http://ftp2.de.debian.org/debian/ 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           ftp.de.debian.org
puppet 2.6.2-5+squeeze4 squeeze           ftp.de.debian.org
puppet 2.7.6-1~bpo60+1  squeeze-backports backports.debian.org
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

http://archive.debian.org is a repository for old Debian releases.

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

deb http://archive.debian.org/debian/ $RELEASE main contrib

for example:

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