apt: The One True Way


Just a quick note of the formatting used in this document.

'$' indicates that the command should be performed by a non-root user.
'#' indicates that the command can only be performed as the root user.
'<....>' is used to denote an option to the said command.

The basics

Debian, and the distributions developed from it (Knoppix, Libranet, Lindows, Ubuntu), use a packaging system based on ".deb" files. Installing and removing packages is pretty straight-forward.

# apt-get install &lt;package&gt;

# apt-get remove &lt;package&gt;

Installing a package will download the latest version of the Debian package, and will also download and install all of the packages that it depends on (if they aren't already installed). Removing a package will also remove all of the packages that depend on it. Purging removes a package, and all of the configuration files that it has (whereas removing keeps the config files).

Configuring apt

The main configuration for apt is in the file /etc/apt/sources.list, which contains a list of sources for packages. These can be CDs or hosts on the Internet (using FTP or HTTP). An typical sources.list file might look like:

deb file:///cdrom/ stable main

deb http://www.uk.debian.org/debian/ stable main non-free contrib
deb http://security.debian.org/ stable/updates main non-free contrib

deb-src http://www.uk.debian.org/debian/ stable main non-free contrib

Each line consists of several space-separated fields. The first is either "deb" or "deb-src" (for binary and source packages, repspectively.) The second is the base URI for the repository. The third is the distribution to use (either the codename, or the development state). The fourth and subsequent fields are the sections to use: usually one or more of main, non-free and contrib.

Note that "Non-US" and its ilk have now been phased out, thanks to changes in American law.

Apt is also configured by files in the /etc/apt/apt-conf.d/ directory. See the man page and documentation for apt for more details.

Keeping up to date

Apt and its friends keep a complete list of the packages that they know about. You can keep this list up to date using:

# apt-get update

You can download the current upgrades to your installed packages by using:

# apt-get upgrade

Occasionally (usually when there's a completely new stable issue of the distribution), some packages won't be upgraded with apt-get upgrade. If this happens, apt-get will tell you that some packages have been "kept back". In this case, you can upgrade those packages as well, using:

# apt-get dist-upgrade

See the section "Packages have been kept back", below, for why this happens.


When Debian removes a package, it will leave behind the conffiles of the package – basically the configuration files that you might have changed. If you want to remove the conffiles as well, you can purge the package:

# apt-get remove --purge &lt;package&gt;

Alternatives to apt-get


apt-get is the original "high-level" Debian package tool, but there are others available as well. The main console (text-based) tool is aptitude, and it can be used in the same way as apt-get:

 1. aptitude install &lt;package&gt;
 1. aptitude remove &lt;package&gt;
 1. aptitude remove &lt;package&gt;_                          Purges package (removes all the config files along with the package)
 1. aptitude purge &lt;package&gt;                            Alternative purge syntax
 1. aptitude install &lt;package1&gt;- &lt;package2&gt;+      Removes package1 and installs package2 at the same time
 1. aptitude update
 1. aptitude upgrade
 1. aptitude dist-upgrade
 1. aptitude install &lt;package&gt;=                         Places a package on "hold"

Note that in recent versions of Aptitude 'upgrade' is replaced by 'safe-upgrade' and 'dist-upgrade' is replaced by 'full-upgrade'

It can also be used in an interactive mode:

$ aptitude

Once into aptitude in the interactive mode single key presses do most of the work: + to mark for install, - to mark for uninstall, = to mark for hold, <return> to look at a package's details, including all the available versions of a package (you can choose between them). If + or - 'breaks' one or more installed packages because of dependencies this will be shown at the top of the screen. Ctrl-u will undo something you've just done. / searches for package names, the package name ~b means a broken package, ~dtext means search the descriptions for text. When you've made your selections g (for get) will show you what's about to happen. At that stage q (for quit) will abort to fiddle some more or a second g will download, install, remove or whatever.

Aptitude is a little more sophisticated in its package management than apt-get, and keeps track of which packages were installed automatically and which were explicitly requested by the user. This means that it can remove unused packages and keep the system as tidy as possible. You should seriously consider using aptitude rather than apt-get.


Dselect was the first interactive package manager for Debian. The user interface is really bad, and it tries to install loads of extra junk when you tell it to install a package.

Dselect? Just say no.


Synaptic is the Gnome version of the package; Kynaptic the KDE version.

Is a GUI (X11) version of aptitude, of the same kind of vintage. It is prettier than aptitude as it uses the gt toolkit which you probably have on your system already. I [JohnLewis] haven't used it much but it has some advantage over aptitude for relative newbies in that it will tell you what files it has installed or what files an uninstalled package depends on. You can add a CDrom or modify your sources.list from the menu. The option to select different views on packages works better than aptitudes views.

I personally find selecting packages to install using the interactive mode of aptitude is a bit hit and miss but synaptic does make this quite easy. However Synaptic has been known to mess things up and I (JL) personally don't trust it for installing things


This is yet another package manager for Debian. It's a little bit like aptitude in terms of options, except that it doesn't have an ncurses front-end. It does, however, have a GUI front-end (gnome): gjig, which is part of the 'wajig' package.

== Information on available packages ===

The list of currently-available packages that apt-get and aptitude maintain can be searched for specific packages, or for words and phrases. The package list is managed using the apt-cache command.

$ apt-cache show &lt;package&gt;

$ apt-cache search words to search for

$ apt-cache depends &lt;package&gt;

$ apt-cache rdepends &lt;package&gt;

or (more accurately):

# aptitude install apt-rdepends
$ apt-rdepends &lt;package&gt;

$ apt-cache search --names-only &lt;package&gt;


$ apt-cache pkgnames &lt;package&gt;

$ dpkg -S filename

One can also use the dlocate program to do this which is a little faster than using the above command since it caches its data:

$ dlocate -S filename

It also has a number of other options which work like the dpkg -foo equivalents.

# apt-file update

Then you can search for the package that will give you a file using

$ apt-file search filename

Digging deeper

The underlying package-handling system is called dpkg. You probably won't have to use dpkg for much, but you can get information about packages using dpkg:

$ dpkg -l                Lists all packages
$ dpkg -l word\*         Lists all packages starting with word
$ dpkg -s &lt;package&gt;      Equivalent to apt-cache show package
$ dpkg -S &lt;file&gt;         List all packages containing files with the given name
$ dpkg -L &lt;package&gt;      List all files owned by package
 1. dpkg -i &lt;file.deb&gt;     Install a local package file
 1. dpkg -r &lt;package&gt;      Attempt to remove a package
 1. dpkg -P &lt;package&gt;      Attempt to remove and purge a package

Some people may find that when using dpkg to see which file belongs to a package that they don't get the answer that they were expecting, thus it may be better to use:

$ dpkg -S $(which &lt;name_of_program&gt;)

Of course, this command can only ever list the owned package if the file was there to begin with. Files that were created outside of the package (but related to it) are obviously not going to show up in your search! This is a very common mistake people make and often leads to large amounts of confusion, and self-destruction.

"Packages have been kept back"

If one or more packages are being "kept back" when you do an aptitude upgrade, it is because installing the new versions of those packages would require another package to be either removed or installed (for example, the original package has been split, or needs a new library). aptitude dist-upgrade will make the necessary changes, installing (or removing) additional packages, whereas aptitude upgrade will always keep the set of installed packages the same.

A quick note on removing things

We've had a couple of people ask on the mailing list "I've just installed (say) the x-window-system package, which has installed a whole load of stuff. Now I want to get rid of it all. How do I do that?"

In brief, you can't do it with apt-get. You can emulate it to an extent, by using deborphan and debfoster. It's probably better to use debfoster since this handles programs, unlike deborphan which only deals with libraries.

However, if you installed it with aptitude in the first place (a good reason for using aptitude rather than apt-get), you should just be able to aptitude remove x-window-system, and anything which was (a) installed automatically and (b) is currently not being required by another package will be removed automatically by aptitude.

ManagingPackages/Apt (last edited 2010-09-06 09:19:41 by AdamTrickett)