Intro to managing packages on Debian GNU/Linux using
dpkg(Good), apt(Better) and aptitude(Best)

dpkg

Debian uses dpkg to install, remove and do everything else related to debian(.deb) packages.

Some basic dpkg commands include:

Install a package, usually a package you downloaded from somewhere else other than apt(more on apt later) mirrors:

dpkg -i package.deb

Remove a package:

dpkg -r package

Purge a package, it removes everything belonging to the package... including configuration files:

dpkg -P package

List installed packages:

dpkg --get-selections

or

dpkg -l

or to only show installed packages:

dpkg -l | grep ^ii

To reconfigure a installed package, for instance X.Org:

dpkg-reconfigure xserver-xorg

dpkg is powerfull but it doenst handle dependencies among other things, for that you have to(and you will) use one of its frontends like apt, aptitude, synaptic(needs X), and others.

P.S. dpkg doesn\'t handle dependencies but... if you need to install a .deb that has a lot of them you can use gdebi(after you install it of course):

gdebi mypackage.deb

It will install the .deb plus all the dependencies it needs, as long as they exist in the apt archives(defined by /etc/apt/sources.list).

All those frontends have a couple of things in common and some of them they share. On of the things they share is /etc/apt/sources.list, this file lists the apt mirrors you want to use(official or otherwise). Check "my" sources.list for some examples/tips.

apt (Advanced Packaging Tool)

apt has two main utils, apt-get to handle packages(install, remove, etc) and apt-cache to handle the packages cache(search, stats, etc)

Both of this programs are simple to use and a apt-get --help or apt-cache --help should be more than enough but here goes:

Update package list; should be done everyday, specially if you use unstable or testing, or everytime you change your sources.list:

apt-get update

Upgrade all installed packages; should be used after and an apt-get update:

apt-get upgrade

Install packages:

apt-get install package

Remove packages:

apt-get remove package

Purge(remove package and configuration):

apt-get --purge remove package

You can handle several packages at the same time, for instance:

apt-get install package1 package2 package3

If you want to install every package that includes gnome on their name then:

apt-get install \'gnome-.*\'

--purge is an option but there are others like -d for downloading packages but not installing them, in case you want to install them later; -s for simulating the operation, this way you can check what apt will do before it really does anything.

Upgrading to a different Debian distribution, there are 3 main distribuitons in Debian: stable, testing and unstable. And then there is experimental...; for instance from stable to testing, this will upgrade your Debian system to the testing distribution. Remember first you must have a testing source in /etc/apt/sources.list:

apt-get dist-upgrade

Every package apt downloads is kept in /var/cache/apt/archives/ and /var/cache/apt/archives/partial(since apt supports resume, packages not fully downloaded are kept here), that means that directory can fill up quite fast, for that apt provides two options... clean and autoclean.

clean; it deletes every package in /var/cache/apt/archives/ and /var/cache/apt/archives/partial:

apt-get clean

autoclean; similar to the clean option but only deletes old, useless, packages:

apt-get autoclean

I alredy talked about the basics on handling packages, but you can\'t really do much if you don\'t know the package names, that\'s where apt-cache comes in...

Search a package; this will search for the string(gnome in this case) in the entire database, package names, descriptions, etc:

apt-cache search gnome

or to search for packages that include gnome and audio:

apt-cache search gnome audio

As you can see that gives a lot of results, so if you only want to search packages that include "gnome" in their name just use:

apt-cache search gnome --names-only

Another common task of apt-cache is to show package information, like dependencies, versions and description:

apt-cache show package

aptitude

aptitude is based on apt so most of the functions are the same as in apt, but it combines apt-get and apt-cache into the same program with some some new features.

Update package list:

aptitude update

Upgrade all installed packages:

aptitude upgrade

Upgrade all installed packages but be more agressive on resolving dependecies, can remove and install new packages. It\'s also used to upgrade from a distribution to another(say from stable to testing):

aptitude dist-upgrade

Install packages:

aptitude install package

Remove packages:

aptitude remove package

Remove packages and it\'s configurations:

aptitude purge package

Show package description and detailed information

aptitude show package

See the changelog of a package, in this case we will check the changelog of gnome-games in experimental:

aptitude changelog gnome-games/experimental

As in apt, aptitude can also handle several packages at the same time, for instance:

aptitude install package1 package2 package3

aptitude search is a bit different...

Search for packages that include the string gnome(for example) in their name:

aptitude search gnome

Search for packages than include gnome in their description:

aptitude search ~dgnome

You can also search by version ~V, maintainer ~m, etc.

To list all installed packages:

aptitude search ~i

Or to list all installed packages that contain gnome on their name:

aptitude search ~ignome

Check for packages available on experimental(as long as you have a source for it):

aptitude search ~Aexperimental

List removed packages that weren\'t purged, their configurations still exist on your system:

aptitude search ~c

If you want to delete ALL those configs do:

dpkg --get-selections | awk \'/deinstall$|purge$/{print $1}\' |xargs dpkg -P

One of the new features,of aptitude, is logging every action, the logs are kept in /var/log/aptitude.

Thanks to logging package management is more efficient, it removes dependencies when you remove the package that installed them. That is great for metapackages (a metapackage is a list of packages needed for a certain task)

For example let\'s remove gnome-games, with apt we would get the following:

sueca:/home/anarka# apt-get --purge remove gnome-games
Reading package lists... Done
Building dependency tree... Done
The following packages will be REMOVED:
  gnome-games*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
Need to get 0B of archives.
After unpacking 1697kB disk space will be freed.
Do you want to continue [Y/n]?

Nice gnome-games package is removed but nothing else, now let\'s try with aptitude:

sueca:/home/anarka# aptitude purge gnome-games
Reading package lists... Done
Building dependency tree... Done
Reading extended state information
Initializing package states... Done
Reading task descriptions... Done
Building tag database... Done
The following packages are unused and will be REMOVED:
  gnome-games-data [1:2.12.1-1] gnome-games-extra-data [2.12.0-1] guile-1.6-libs [1.6.7-1.1]
  libguile-ltdl-1 [1.6.7-1.1] libqthreads-12 [1.6.7-1.1] librsvg2-common [2.12.7-1]
The following packages will be REMOVED:
  gnome-games{p} [1:2.12.1-1]
0 packages upgraded, 0 newly installed, 7 to remove and 0 not upgraded.
Need to get 0B of archives. After unpacking 22.2MB will be freed.
Do you want to continue? [Y/n/?] n

This is much more efficient, not only it removes gnome-games, but it also removes packages that aren\'t needed anymore due to the removal of the package. Of course if you want good results you should only use aptitude, since apt doesn\'t log anything, so you can\'t just hope aptitude will know what you did with apt.

If you want to customize apt or aptitude use /etc/apt/apt.conf, i have the following lines in there:

APT::Get::Show-Upgraded "true";
APT::Acquire::Retries "5";
APT::Cache-Limit 22582912;
APT::Get::Purge;
Aptitude::CmdLine::Show-Versions "true";
Aptitude::CmdLine::Verbose "5";
Aptitude::CmdLine::Always-Prompt "true";
Aptitude::CmdLine::Package-Display-Format "%c%a%M %p# %15v %15V - %d#";

Updated in 2006/07/23 anarka@anarka.org