Using apt-get and aptitude

Slashdot it! Delicious Share on Facebook Tweet! Digg!


As a Pair


Installing and removing software is a required task for every package manager. Correctly managing a Debian system calls for efficient tools such as apt-get and aptitude.

Tools like apt-get and aptitude resolve dependencies and automatically remove programs that are no longer needed. They also clean up, update, and configure software on a Debian-based systems, such as Ubuntu, relying on mechanisms of package management for large-scale operations.

Both programs are easy to use for simple tasks (see the "Basics" box), but, with a little know-how, you can draw upon a very complete set of the tools and accomplish even complex tasks quickly and easily.


Part 1 of this workshop [1] showed how to classify apt and aptitude in the various levels of Debian package management. It introduced the programs' very similar options and parameters, while taking into account their idiosyncrasies.

In this part, we'll focus on the various configuration options and especially their effective use. Apt wins in speed, while aptitude wins in installing and removing packages in a single step along with its comprehensive selection of packages using search patterns.

Default Settings

The apt and aptitude distribution maintainers usually provide default configurations. In the past, these were included in two files in the /etc/apt directory. The /etc/apt/apt.conf file handled the system-wide behavior [2] of apt and aptitude, whereas the /etc/apt/preferences file set the priorities for packages and package groups. Both of these files are optional on current systems.

Over time, the developers modularized the apt system configuration piece by piece. Since 2001, they have separated the configuration files into two separate directories – with the same filenames as before except ending with .d [3]. Following /etc/apt/apt.conf.d/, version 0.7.22 in 2009 (i.e., between 07.20.2 "Lenny" and "Squeeze") came /etc/apt/preferences.d/ and, in 2010, /etc/apt/trusted.gpg.d/.

These directories further prioritized packages and included additional key ring files, such as the GPG key to verify backports, which are updated, bug-free, or functionally enhanced packages applied to older Debian releases to keep up the system up to date.

This directory structure allows software maintainers to ensure through their own configuration files that additional operations can run before or after installing programs with apt or aptitude.

All programs based on apt use the files in /etc/apt/ and use the identical file format, which recalls run-parts [4]. Files in these directories must follow certain naming conventions. Therefore, apt ignores files missing the .list extension in /etc/apt/sources.list.d/.

Additionally, some programs (aptitude in particular) put configuration files in other locations. Thus, aptitude saves its own system-wide defaults in /usr/share/aptitude/aptitude-defaults, which apt ignores [5].

If you change settings in the curses-based aptitude interface, parameters end up in the .aptitude/config file in your home directory and apply only to you.

To apply the change system-wide transfer the contents as root user from .aptitude/config to /etc/apt/apt.conf or into a new file in the /etc/apt/apt.conf.d/ directory.

After a standard CD or DVD installation, you can find four files in the /etc/apt/apt.conf.d/ directory whose names begin with a two-digit sequence (Table 1).

Table 1: Configuration Files for Apt

00trustcdrom Installation List of trusted sources
01autoremove Package apt List of packages with details on whether the system can automatically remove each
50unattended-upgrades Package unattended-upgrades List of packages that the system can independently update
70debconf Package debconf Details about the actions before and after installing a package with pgkg, version (Debian release) used, size of package cache, and source response time

Apt works the files with these prefixes in ascending order of name [6]. The remaining files can be named as desired, but should normally correspond to the originating package name.

Apt ignores files with names ending in .disabled or a tilde (~), with the latter being an editor backup file. If dpkg modifies configuration files, it also creates copies without any effect on apt behavior.

You can tell which configuration apt and aptitude actually uses with the apt-config program from the apt package. If you invoke it with the dump option, you get a complete overview of all configured values (Figure 1). If you want to supplement the configuration, it's usually best to add a corresponding fragment from the /etc/apt/apt.conf.d/ directory.

Figure 1: The apt-config command displays the current settings at a glance.

Single-user systems can usually omit most apt configurations. The situation gets interesting if you want to maintain a current software state or exclude certain packages from installing despite the existence of a current package. The same goes for automatically installing recommended packages or if network access is done through a proxy server [7][8][9].

The subtle differences between apt and aptitude are made clear, among other things, by the differences in removing "orphaned" packages. These packages are created when the package manager doesn't remove all dependencies during an uninstall that were necessary only for the removed package but in no way affect any newly installed software.

Apt-get simply indicates that such orphaned packages exist, whereas aptitude automatically removes them. The related configuration command options and settings are shown in Table 2.

Table 2: Automatic Removal

Removing apt-get --auto-remove <package> aptitude remove <package>
Not removing dependencies apt-get remove <package> aptitude -o Aptitude::Delete-Unused=false remove <package>
Configuration options APT::Get::AutomaticRemove Aptitude::Delete-Unused
Default value false true

In One Step

Apt-get lets you reverse the operation of both the subcommands install and remove. For apt-get, you add a plus or minus sign to each package name. With a minus sign added to the package name for apt-get install, for example, you can remove it instead of installing it.

This functionality turns out to be useful when you set up a package that has alternative dependencies where you want to exclude certain ones. The stumpwm package uses a Lisp interpreter written in Stump Window Manager [10], but it doesn't settle on a particular one. Therefore, one of the three packages (clisp-module-clx, cl-clx-sbcl, or cmucl-source) should suffice. If you don't have any of them installed, apt-get usually selects the first package. If that's not what you want, you can use the following command to deselect it, in which case apt-get uses the second one instead:

# apt-get install stumpwm clisp-module-clx

Aptitude provides far more options in this respect. On one hand, it allows these corrections with other subcommands, such as full-upgrade, safe-upgrade, markauto or hold. On the other hand, it provides far more actions that you can add with tags to the name of the package (Table 3).

Table 3: Actions in Aptitude

+ Install package
+M Install package and mark as automatically installed
- Remove package
_ Purge package and its configuration
: Retain package (e.g., do not update)
= Put package "on hold"
&M Mark package as automatically installed
&m Mark package as not automatically installed
&BD Satisfy build dependencies of the package

The example in Listing 1 shows these options in practice. With one command, aptitude updates the lintian package, installs the htop package and any missing build dependencies (libncurses5-dev in this case), removes the tasksel package along with its dependencies, and sets the ccal package as "automatically installed." Package manager then removes Ccal because no other package depends on it. All other packages not named remain in their current state, even if a newer version is available: aptitude full-upgrade processes only the specified packages.

Listing 1

Aptitude Options in Practice

# aptitude full-upgrade lintian htop+ 'htop&BD' tasksel- 'ccal&M'
The following NEW packages will be installed:
  htop libncurses5-dev
The following packages will be UPGRADED:
The following packages will be KEPT BACK:
  iceweasel libmozjs10d xulrunner-10.0
The followihhhhng packages will be REMOVED:
  ccal{a} tasksel tasksel-data{a}
1 packages upgraded, 2 newly installed, 3 to remove and 3 not upgraded.

Buy this article as PDF

Express-Checkout as PDF

Pages: 5

Price $0.99
(incl. VAT)

Buy Ubuntu User

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content