Using aptitude from the command line

In addition to its visual interface described in the previous section, aptitude can be used to manage packages directly from the command-line in the same way that you would use apt-get. This section covers the most common aptitude command-line actions; for more information, see the aptitude command-line reference.

In general, a command-line invocation of aptitude will look like this:

aptitude action [arguments...]

action tells aptitude what action it is to take; the remaining arguments are used in an option-specific fashion. Typically they will consist of package names and command-line switches[4].

The most important actions are:

aptitude update

This command updates the package lists, as if you had entered the visual interface and pressed u.

aptitude safe-upgrade

This command will upgrade as many packages as it can upgrade without removing existing packages.

It is sometimes necessary to remove one package in order to upgrade another; this command is not able to upgrade packages in such situations. Use the full-upgrade command to upgrade those packages as well.

aptitude full-upgrade

Like safe-upgrade, this command will attempt to upgrade packages, but it is more aggressive about solving dependency problems: it will install and remove packages until all dependencies are satisfied. Because of the nature of this command, it is possible that it will do undesirable things, and so you should be careful when using it.

[Note]Note

For historical reasons, this command was originally named dist-upgrade, and that name is still recognized by aptitude.

aptitude [ install | remove | purge ] pkg1 [pkg2...]

These commands install, remove, or purge[5] the specified packages. Installing a package which is already installed but can be upgraded will cause it to be upgraded.

aptitude search pattern1 [pattern2...]

This command searches for packages whose name contains any of the given patterns, printing the result to the terminal. In addition to just being a string of text, each pattern can be a search pattern as described in the section called “Search patterns”. [6] For instance, aptitude search gnome kde will list all packages whose name contains either gnome or kde.

aptitude show pkg1 [pkg2...]

Prints information about each pkg to the terminal.

The commands that install, upgrade, and remove packages all accept the parameter -s, which stands for simulate. When -s is passed on the command line, the program performs all the actions it would normally perform, but does not actually download or install/remove any files.

aptitude will sometimes present a prompt like this:

The following NEW packages will be automatically installed:
  space-orbit-common 
The following NEW packages will be installed:
  space-orbit space-orbit-common 
0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 3200kB of archives. After unpacking 8413kB will be used.
Do you want to continue? [Y/n/?]

In addition to the obvious options of Yes and No, a number of commands are available which can be used to change the information displayed at the prompt, or to specify further actions. For instance, typing s will display or hide information about how much space each package will use:

Do you want to continue? [Y/n/?] s

Size changes will be shown.

The following NEW packages will be automatically installed:
  space-orbit-common <+8020kB> 
The following NEW packages will be installed:
  space-orbit <+393kB> space-orbit-common <+8020kB> 
0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 3200kB of archives. After unpacking 8413kB will be used.
Do you want to continue? [Y/n/?]

Similarly, typing d will display information about automatically installed or removed packages:

The following NEW packages will be automatically installed:
  space-orbit-common (D: space-orbit)
The following NEW packages will be installed:
  space-orbit space-orbit-common 
0 packages upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 3200kB of archives. After unpacking 8413kB will be used.

This shows that space-orbit-common is being installed because space-orbit depends on it. You can see the entire list of possible entries by entering ? at the prompt.

If your request violates dependencies in a way that cannot be trivially resolved, aptitude will ask you what to do:

The following packages are BROKEN:
  libsdl1.2debian
The following packages will be REMOVED:
  libsdl1.2debian-alsa
.
.
.
The following actions will resolve these dependencies:

Install the following packages:
libsdl1.2debian-all [1.2.12-1 (unstable)]

Score is 41

Accept this solution? [Y/n/q/?]

Typing y (or simply pressing enter) will accept the proposed solution. Typing n will display the next best solution:

Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:

Install the following packages:
libsdl1.2debian-esd [1.2.12-1 (unstable)]

Score is 19

Accept this solution? [Y/n/q/?]

As with the main command-line prompt, you can perform a number of additional actions, including manually altering the states of packages, from the dependency resolution prompt. Type ? to see a complete list.

Typing q will abort the automatic resolver and allow you to resolve the dependencies manually:

Accept this solution? [Y/n/q/?] q
aptitude failed to find a solution to these dependencies.  You can solve them yourself by hand or type 'n' to quit.
The following packages have unmet dependencies:
  libsdl1.2debian: Depends: libsdl1.2debian-alsa (= 1.2.12-1) but it is not installable or
                            libsdl1.2debian-all (= 1.2.12-1) but it is not installable or
                            libsdl1.2debian-esd (= 1.2.12-1) but it is not installable or
                            libsdl1.2debian-arts (= 1.2.12-1) but it is not installable or
                            libsdl1.2debian-oss (= 1.2.12-1) but it is not installable or
                            libsdl1.2debian-nas (= 1.2.12-1) but it is not installable or
                            libsdl1.2debian-pulseaudio (= 1.2.12-1) but it is not installable
Resolve these dependencies by hand? [N/+/-/_/:/?]

You can use any of the package manipulation commands to resolve the broken dependencies (type ? for a full list of the available commands). Type n or press enter to quit aptitude:

Resolve these dependencies by hand? [N/+/-/_/:/?] n
Abort.

For complete documentation of the command-line features of aptitude, see Command-line reference.



[4] A switch is a letter preceded by a hyphen: for instance, -a, -v, etc.

[5] Purging a package removes the package, as well as all its configuration files.

[6] In fact, the same is true of the commands that take packages as arguments, such as install or show.