apt-get and aptitude

Filed in: Documentation.Apt-getAndAptitude · Modified on : Mon, 06 Sep 10

1.  General information

The GNU/Linux systems which use the Debian package management system (.deb packages - Debian software packages) usually make available several ways to manage packages. The base system mostly used is Advanced Packaging Tool (APT). It includes the ability to handle a GPG keyring, enabling a secure way to use repositories (Secure APT).

Also in gNewSense, package management is handled using the Debian package management system (gNewSense DeltaH packages are usually from Ubuntu most of which are ultimately from Debian, gNewSense MetaD packages come directly from Debian).

Packages are usually available online, at the appropriate repository. With a command-line interface or a terminal, the commands which are used to query the repositories and manage packages are apt-get and aptitude. In a graphical environment the application software mostly used is Synaptic, a graphical interface that provides almost all the features of aptitude.

Packages may also be available offline, in which case can be handled in a terminal by the dpkg command. A widespread used graphical interface for dpkg is the GDebi installer.

The list of the repositories used by the system is in the /etc/apt/sources.list file. The preferred way to change the repository info and manage their signature keys is through the Software Sources tool (menu: System > Administration > Software Sources).

Package maintainers create source and binary packages for many programs and platforms, from a variety of sources; this means most programs, over different platforms, can be installed or removed in a single step.

The two programs apt-get and aptitude have a very similar command-line functionality (aptitude also has a curses interface). However, aptitude has a better support for removing unneeded dependencies. Either program will install package B if package A requires it. However, aptitude will also remove package B if you remove package A (the version of apt-get in gNewSense DeltaD will not). In general, aptitude can accept all of apt-get's options, so, generally, it is simplest to use only one of them.

2.  Managing packages

Please remember that the preferred way to change the repository info and manage the apt keys is through the Software Sources tool (menu: System > Administration > Software Sources).

In the continuation:
<package> or <packageN> (N=1,2,...) means the package(s) name(s)
<version> means the package version number
<desc> means the package description

2.1  Installing packages

To install one or more packages and all their dependencies (to specify a package version add =<version> to the package name):

$ sudo apt-get install <package1> <package2> <...>

or

$ sudo aptitude install <package1> <package2> <...>

2.2  Removing packages

To remove one or more packages:

$ sudo apt-get remove <package1> <package2> <...>

or

$ sudo aptitude remove <package1> <package2> <...>

To remove one or more packages and all of their settings (eg. configuration files):

$ sudo apt-get --purge remove <package1> <package2> <...>

or

$ sudo aptitude purge <package1> <package2> <...>

Note that usually purging is not necessary, but it may be if a program installation fails or there are package conflicts.

2.3  Reinstalling packages

To reinstall one or more packages:

$ sudo apt-get --reinstall install <package1> <package2> <...>

or

$ sudo aptitude reinstall <package1> <package2> <...>

2.4  Updating the package list

To update the list of the available packages in the repositories:

$ sudo apt-get update

or

$ sudo aptitude update

2.5  Updating the system

To update all the installed packages to the last available version without installing or removing packages:

$ sudo apt-get upgrade

or

$ sudo aptitude upgrade

or

$ sudo aptitude safe-upgrade

To update all the installed packages to the last available version installing or removing other packages if needed (be aware: the upgrade option keeps also the old version packages when they need to satisfy other packages dependencies, but the dist-upgrade option do not! so the upgrade option is more conservative than the dist-upgrade option):

$ sudo apt-get dist-upgrade

or

$ sudo aptitude dist-upgrade

2.6  Cleaning the apt cache

To remove all the downloaded and cached packages:

$ sudo aptitude clean

To remove just the unavailable packages from cache:

$ sudo aptitude autoclean

2.7  Downloading .deb packages

To download in the current directory the most recent available version of a .deb package:

$ sudo aptitude download <package>

2.8  Searching for packages

To find the packages which name or description macthes a search string (regular expressions may be used):

$ apt-cache search <desc>

or

$ aptitude search <desc>

2.9  Showing package information:

To show a package info:

$ apt-cache show <package>

or

$ aptitude show <package>

To show the dependencies of a package:

$ apt-cache depends <package>

or

$ aptitude show --show-deps <package>

To show detailed info about the available versions of a package and their dependencies:

$ apt-cache showpkg <package>

3.  Managing the apt keyring

Please remember that the preferred way to change the repository info and manage the apt keys is through the Software Sources tool (menu: System > Administration > Software Sources).

In the continuation:
<key-id> means the key ID
<keyserver> means the URI of a keyserver
<URI-of-keyfile> means the URI of a downloadable key file

3.1  Showing the keyring

To show the installed apt keys:

$ sudo apt-key list

3.2  Downloading and installing keys

To download the signature key file (it needs to known the URI of the key file) and after install it:

$ wget <URI-of-keyfile>
$ sudo apt-key add <keyfile>

Example (gNewSense DeltaD repository key):

$ wget http://archive.gnewsense.org/gnewsense-deltad/dists/deltad/Release.gpg
$ sudo apt-key add Release.gpg

To download and install the signature key from a keyserver (it needs to know the key ID):

$ sudo apt-key adv --keyserver <keyserver> --recv-keys <key-id>

Example (TOR project repository key):

$ sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 886DDD89

4.  Additional resources


Page last modified on September 06, 2010, at 12:28 PM

gNewSense is a project developed by volunteers all over the world and it's supported by the Free Software Foundation.

The content in this Web site can be used as follows:

All documentation is available under the terms of the GFDL with no invariant sections. ( note on the license )

Artwork is Free Cultural Work and is available under the terms of the cc-by-sa license.