Product SiteDocumentation Site

6.2. aptitude, apt-get und apt Befehle

APT is a vast project, whose original plans included a graphical interface. It is based on a library which contains the core application, and apt-get is the first front end — command-line based — which was developed within the project. apt is a second command-line based front end provided by APT which overcomes some design mistakes of apt-get.
Both tools are built on top of the same library and are thus very close, but the default behavior of apt has been improved for interactive use and to actually do what most users expect. The APT developers reserve the right to change the public interface of this tool to further improve it. On the opposite, the public interface of apt-get is well defined and will not change in any backwards incompatible way. It is thus the tool that you want to use when you need to script package installation requests.
Numerous other graphical interfaces then appeared as external projects: synaptic, aptitude (which includes both a text mode interface and a graphical one — even if not complete yet), wajig, etc. The most recommended interface, apt, is the one that we will use in the examples given in this section. Note, however, that apt-get and aptitude have a very similar command line syntax. When there are major differences between these three commands, these will be detailed.

6.2.1. Initialisierung

For any work with APT, the list of available packages needs to be updated; this can be done simply through apt update. Depending on the speed of your connection and configuration, the operation can take a while, since it involves downloading a certain number of (usually compressed) files (Packages, Sources, Translation-language-code), which have gradually become bigger and bigger as Debian has developed (at least 10 MB of data for the main section). Of course, installing from a CD-ROM/DVD set does not require any downloading — in this case, the operation is very fast.

6.2.2. Installieren und Entfernen

With APT, packages can be added or removed from the system, respectively with apt install package and apt remove package. In both cases, APT will automatically install the necessary dependencies or delete the packages which depend on the package that is being removed. The apt purge package command involves a complete uninstallation by deleting the configuration files as well.
If the file sources.list mentions several distributions, it is possible to give the version of the package to install. A specific version number can be requested with apt install package=version, but indicating its distribution of origin (Stable, Testing or Unstable) — with apt install package/distribution — is usually preferred. With this command, it is possible to go back to an older version of a package (if, for instance, you know that it works well), provided that it is still available in one of the sources referenced by the sources.list file. Otherwise the snapshot.debian.org archive can come to the rescue (see sidebar WEITERE SCHRITTE Alte Paketversionen: snapshot.debian.org).

Beispiel 6.4. Installation of the Unstable version of spamassassin

# apt install spamassassin/unstable
If the package to install has been made available to you under the form of a simple .deb file without any associated package repository, it is still possible to use APT to install it together with its dependencies (provided that the dependencies are available in the configured repositories) with a simple command: apt install ./path-to-the-package.deb. The leading ./ is important to make it clear that we are referring to a filename and not to the name of a package available in one of the repositories.

6.2.3. Das System aktualisieren

Regelmäßige Aktualisierungen werden empfohlen, weil sie die neuesten Sicherheitsupdates beinhalten. Zum Aktualisieren benutzen Sie apt upgrade, apt-get upgrade oder aptitude safe-upgrade (natürlich nach apt-get update). Dieser Befehl sucht nach installierten Paketen, die aktualisiert werden können, ohne irgendwelche Pakete zu entfernen. Mit anderen Worten, es ist das Ziel, eine minimal invasive Aktualisierung sicher zu stellen. apt-get ist ein wenig anspruchsvoller als aptitude oder apt, weil es sich weigert, Pakete zu installieren, die zuvor nicht installiert waren.
apt wählt grundsätzlich die neueste Versionsnummer aus (außer bei Paketen aus Experimental und stable-backports, die standardmäßig ignoriert werden, unabhängig von ihrer Versionsnummer). Falls Sie Testing oder Unstable in Ihrer sources.list angegeben haben, wird apt upgrade den größten Teil Ihres Stable-Systems auf Testing oder Unstable umstellen, was möglicherweise nicht Ihre Absicht war.
To tell apt to use a specific distribution when searching for upgraded packages, you need to use the -t or --target-release option, followed by the name of the distribution you want (for example, apt -t stable upgrade). To avoid specifying this option every time you use apt, you can add APT::Default-Release "stable"; in the file /etc/apt/apt.conf.d/local.
Für wichtigere Aktualisierungen, wie den Übergang von einer Debian-Hauptversion zur nächsten, müssen Sie apt full-upgrade benutzen. Mit dieser Anweisung vollzieht apt die Aktualisierung selbst dann, wenn es einige veraltete Pakete entfernen oder neue Abhängigkeiten installieren muss. Dies ist ebenso der Befehl, den Benutzer verwenden, die täglich mit Debians Unstable-Veröffentlichung arbeiten und deren Entwicklung tagtäglich verfolgen. Es ist so einfach, dass es kaum einer Erklärung bedarf: APTs Ansehen begründet sich in dieser großartigen Funktionalität.
Anders als apt und aptitude, kennt apt-get nicht den full-upgrade Befehl. Sie sollten statt dessen apt-get dist-upgrade (”distribution upgrade”) verwenden, den historischen und gut bekannten Befehl, der auch von apt und aptitude zur Vereinfachung für den Benutzer verwendbar ist.
The results of these operations are logged into /var/log/apt/history.log and /var/log/apt/term.log, whereas dpkg keeps its log in a file called /var/log/dpkg.log.

6.2.4. Konfigurationsoptionen

Besides the configuration elements already mentioned, it is possible to configure certain aspects of APT by adding directives in a file of the /etc/apt/apt.conf.d/ directory or /etc/apt/apt.conf itself. Remember, for instance, that it is possible for APT to tell dpkg to ignore file conflict errors by specifying DPkg::options { "--force-overwrite"; }.
Falls auf das Web nur über einen Web-Proxy zugegriffen werden kann, fügen Sie eine Zeile wie Acquire::http::proxy "http://IhrProxy:3128" hinzu. Für einen FTP-Proxy schreiben Sie Acquire::ftp::proxy "ftp://IhrProxy". Um mehr über die Konfigurationsoptionen heraus zu finden, lesen Sie die Handbuchseite apt.conf(5) mit dem Befehl man apt.conf (für Einzelheiten zu Handbuchseiten siehe Abschnitt 7.1.1, „Handbuchseiten“).

6.2.5. Paketprioritäten verwalten

Einer der wichtigsten Aspekte bei der Konfiguration von APT ist die Verwaltung der Prioritäten, die jeder Paketquelle zugeordnet sind. Möchten Sie zum Beispiel eine stabile Distribution durch ein oder zwei neuere Pakete aus Testing, Unstable oder Experimental erweitern? Es ist möglich, jedem verfügbaren Paket eine Priorität zuzuweisen (dasselbe Paket kann mehrere Prioritäten haben, abhängig von seiner Version oder der Distribution, in der es vorkommt). Diese Prioritäten beeinflussen APTs Verhalten: Für jedes Paket wird die Version mit der höchsten Priorität ausgewählt (außer wenn diese Version älter ist, als die installierte und wenn ihre Priorität geringer als 1000 ist).
APT definiert verschiedene Standard-Prioritäten. Jede installierte Paketversion hat die Priorität 100. Eine nicht installierte Version erhält standardmäßig die Priorität 500, diese kann aber auf 990 angehoben werden, falls sie Teil der Ziel-Veröffentlichung ist (diese wird durch die Befehlszeilenoption -t oder die Konfigurationsanweisung APT::Default-Release festgelegt).
You can modify the priorities by adding entries in a file in /etc/apt/preferences.d/ or the /etc/apt/preferences file with the names of the affected packages, their version, their origin and their new priority.
APT will never install an older version of a package (that is, a package whose version number is lower than the one of the currently installed package) except if its priority is higher than 1000 (or it is explicitely requested by the user, see Abschnitt 6.2.2, „Installieren und Entfernen“). APT will always install the highest priority package which follows this constraint. If two packages have the same priority, APT installs the newest one (whose version number is the highest). If two packages of same version have the same priority but differ in their content, APT installs the version that is not installed (this rule has been created to cover the case of a package update without the increment of the revision number, which is usually required).
In more concrete terms, a package whose priority is
< 0
will never be installed,
1..99
will only be installed if no other version of the package is already installed,
100..499
will only be installed if there is no other newer version installed or available in another distribution,
500....989
will only be installed if there is no newer version installed or available in the target distribution,
990..1000
will be installed except if the installed version is newer,
> 1000
will always be installed, even if it forces APT to downgrade to an older version.
When APT checks /etc/apt/preferences and /etc/apt/preferences.d/, it first takes into account the most specific entries (often those specifying the concerned package), then the more generic ones (including, for example, all the packages of a distribution). If several generic entries exist, the first match is used. The available selection criteria include the package's name and the source providing it. Every package source is identified by the information contained in a Release file that APT downloads together with the Packages files. It specifies the origin (usually “Debian” for the packages of official mirrors, but it can also be a person's or an organization's name for third-party repositories). It also gives the name of the distribution (usually Stable, Testing, Unstable or Experimental for the standard distributions provided by Debian) together with its version (for example, 10 for Debian Buster). Let's have a look at its syntax through some realistic case studies of this mechanism.
Angenommen, Sie wollen nur Pakete aus der stable-Version von Debian verwenden. Pakete anderer Versionen sollen nicht installiert werden, es sei denn, dies wird explizit gewünscht. In dem Falle können Sie folgenden Eintrag in der Datei /etc/apt/preferences vornehmen:
Package: *
Pin: release a=stable
Pin-Priority: 900

Package: *
Pin: release o=Debian
Pin-Priority: -10
a=stable bestimmt den Namen der ausgewählten Distribution. o=Debian beschränkt den Umfang auf Pakete mit der Herkunft "Debian".
Let's now assume that you have a server with several local programs depending on the version 5.24 of Perl and that you want to ensure that upgrades will not install another version of it. You could use this entry:
Package: perl
Pin: version 5.24*
Pin-Priority: 1001
To gain a better understanding of the mechanisms of priority and distribution or repository properties to pin do not hesitate to execute apt-cache policy to display the default priority associated with each package source, or apt-cache policy package to display the default priority for each available version and source of a package as explained in TIPP apt-cache policy.
The reference documentation for the files /etc/apt/preferences and /etc/apt/preferences.d/ is available in the manual page apt_preferences(5), which you can display with man apt_preferences.

6.2.6. Mit mehreren Distributionen arbeiten

Das ausgezeichnete Werkzeug apt versucht, die Pakete von anderen Distributionen zu übernehmen. Nachdem man vielleicht ein Stable System installiert hat, möchte man evtl. ein Software Paket aus Testing oder Unstable ausprobieren, ohne all zu weit vom ursprünglichen Zustand des Systems abzuweichen.
Selbst wenn Sie beim Mischen von Paketen aus unterschiedlichen Distributionen gelegentlich auf Probleme stossen sollten, apt verwaltet ein solches Nebeneinander sehr gut und beschränkt die Risiken sehr effektiv. Die beste Vorgehensweise ist, alle benutzten Distributionen in /etc/apt/sources.list einzutragen (es gibt Leute, die immer alle drei Distributionen eintragen, aber beachten Sie, dass Unstable nur für erfahrene Anwender vorgesehen ist) und die Referenzdistribution mit dem APT::Default-Release Parameter fest zu legen (siehe Abschnitt 6.2.3, „Das System aktualisieren“).
Nehmen wir einmal an, Stable sei Ihre Referenzdistribution aber Testing und Unstable seien auch in Ihrer sources.list-Datei gelistet. In diesem Fall können Sie apt install package/testing nutzen, um ein Paket aus Testing zu installieren. Sollte die Installation auf Grund von nicht auflösbaren Abhängigkeiten scheitern, lassen sich diese Abhängigkeiten in Testing durch Angabe des -t testing Parameters lösen. Dies gilt gleichermassen für Unstable.
In dieser Situation werden Aktualisierungen (upgrade und full-upgrade) in Stable vorgenommen, ausgenommen Pakete, die bereits auf eine andere Distribution aktualisiert wurden: Diese folgen den Aktualisierungen der anderen Distributionen. Wir erklären dieses Verhalten mit Hilfe der von APT gesetzten Standardprioritäten weiter unten. Benutzen Sie apt-cache policy (siehe Seitenleiste TIPP apt-cache policy), um die gesetzten Prioritäten zu überprüfen.
Alles beruht auf der Tatsache, dass APT nur Pakete gleich oder höher der installierten Version in Betracht zieht (unter der Annahme das /etc/apt/preferences für kein Paket eine Priorität größer als 1000 erzwingt).
Lassen Sie uns annehmen, Sie hätten Version 1 eines ersten Pakets aus Stable installiert und Version 2 und 3 wären in Testing bzw. in Unstable verfügbar. Die installierte Version hat eine Priorität von 100 aber die Version aus Stable (genau die gleiche) hat eine Priorität von 990 (weil sie Bestandteil der Zieldistribution ist). Pakete in Testing und Unstable haben eine Priorität von 500 (die Standardpriorität einer nicht installierten Version). Der Gewinner ist daher die Version 1 mit der Priorität 990. Das Paket "bleibt in Stable”.
Let's take the example of another package whose version 2 has been installed from Testing. Version 1 is available in Stable and version 3 in Unstable. Version 1 (of priority 990 — thus lower than 1000) is discarded because it is lower than the installed version. This only leaves version 2 and 3, both of priority 500. Faced with this alternative, APT selects the newest version, the one from Unstable. If you don't want a package installed from Testing to migrate to Unstable, you have to assign a priority lower than 500 (490 for example) to packages coming from Unstable. You can modify /etc/apt/preferences to this effect:
Package: *
Pin: release a=unstable
Pin-Priority: 490

6.2.7. Automatisch installierte Pakete nachverfolgen

One of the essential functionalities of apt is the tracking of packages installed only through dependencies. These packages are called “automatic”, and often include libraries.
With this information, when packages are removed, the package managers can compute a list of automatic packages that are no longer needed (because there is no “manually installed” packages depending on them). apt-get autoremove or apt autoremove will get rid of those packages. aptitude does not have this command because it removes them automatically as soon as they are identified. In all cases, the tools display a clear message listing the affected packages.
Es ist eine gute Idee, jedes Paket als automatisch zu markieren, das man nicht direkt benötigt, damit diese automatisch entfernt werden, wenn sie nicht weiter benötigt werden. apt-mark auto Paket markiert das betreffenbde Paket als automatisch, während apt-mark manual Paket das Gegenteil tut. aptitude markauto und aptitude unmarkauto arbeiten gleichermaßen, obwohl sie mehr Möglichkeiten bieten, viele Pakete auf einmal zu markieren (siehe Abschnitt 6.5.1, „aptitude). Die konsolenbasierte interaktive Benutzerschnittstelle von aptitude macht es ebenfalls leicht, das "automatisch"-Flag zu überprüfen.
Manchmal möchte man wissen, warum ein automatisch installiertes Paket installiert wurde. Um auf der Kommandozeile an diese Information zu gelangen, können Sie aptitude why Paket benutzen (apt und apt-get haben keine entsprechende Funktion):
$ aptitude why python-debian
i   aptitude         Suggests apt-xapian-index
p   apt-xapian-index Depends  python-debian (>= 0.1.14)