6.2. aptitude
、apt-get
、apt
コマンド
APT は巨大なプロジェクトで、当初の予定ではグラフィカルインターフェースを含んでいました。APT はライブラリに基づいており、そのライブラリにはコアアプリケーションが含まれています。
apt-get
は最初のコマンドラインベースフロントエンドで、APT プロジェクト内で開発されました。
apt
は APT から提供されているもう一つのコマンドラインベースフロントエンドで、
apt-get
の持っていた設計上のミスを克服しています。
どちらのツールも同じライブラリから構築されているため、非常によく似ています。しかしながら、apt
のデフォルトの挙動は対話的利用の観点から改善され、多くのユーザの予想通りに動作します。APT の開発者はさらにこれを改善するために apt
のユーザ向けインターフェースを変更する権利を保有しています。逆に、apt-get
のユーザ向けインターフェースは明確に定義されており後方互換性がなくなることはないでしょう。このため、スクリプトでパッケージをインストールする場合には apt-get
を使うと良いでしょう。
APT の数多くのグラフィカルインターフェースは外部プロジェクトとして生まれました。たとえば synaptic
、aptitude
(テキストとグラフィカルモードインターフェースの両方があり、グラフィカルモードインターフェースはまだ完成していません)、wajig
などが生まれました。最も推奨されるインターフェースは apt
で、この節では apt
を例に使います。apt
のコマンドライン構文と apt-get
や aptitude
のコマンドライン構文はよく似ていることに注意してください。 この3つの間に大きな違いがある場合は、その違いを詳しく述べます。
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 14-18 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.
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 and data 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
「GOING FURTHER Old package versions: snapshot.debian.org
and archive.debian.org
」).
例 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 the name of a file and not to the name of a package available in one of the repositories.
最新のセキュリティ更新を入手するために、定期的にアップグレードを行うことをお勧めします。アップグレードを行うには (もちろん apt update
を実行した後に) apt upgrade
、apt-get upgrade
、aptitude safe-upgrade
を実行してください。これらのコマンドは他のパッケージを削除せずにアップグレードできるインストール済みパッケージだけを探します。言い換えれば、最低限可能なアップグレードを行います。apt-get
のアップグレードパッケージの選択規則は aptitude
や apt
よりも少し条件が厳しいです。なぜなら apt-get upgrade
は現在のパッケージ構成を変えないからです。つまりパッケージの新パージョンで導入された新しい依存関係により現在インストールされていないパッケージをインストールする必要が生じた場合はパッケージの新パージョンをインストールしないからです。
通常 apt
は最新のバージョンをインストールします (ただし実験版と安定版バックポートのパッケージはバージョン番号に関わらず明示的に指定しない限りインストールされません)。sources.list
の中でテスト版や不安定版を指定した場合、apt upgrade
は安定版システムのほとんどをテスト版や不安定版に変更します。これはあなたが望んでいないことかもしれません。
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
.
より重要なアップグレード、たとえば Debian のメジャーバージョンをアップグレードするなどの場合、apt full-upgrade
を使ってください。apt full-upgrade
を実行した場合、apt
はアップグレードに伴う新しい依存関係により不要となったパッケージを削除します。また、apt full-upgrade
は Debian 不安定版 リリースを日常的に使い、毎日開発進化を追いかけているユーザが使うコマンドです。これは説明がほとんど必要ないくらいとても単純です。そして APT の評判はこの偉大なる機能性が担っています。
apt
と異なり、aptitude
および apt-get
では full-upgrade
コマンドを使うことができません。その代わり、apt-get dist-upgrade
(「ディストリビューションアップグレード」) を使ってください。dist-upgrade コマンドは歴史的かつよく知られており、apt
と aptitude
はユーザの利便性を考慮して dist-upgrade を受け付けます。
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
.
既に説明した設定項目に加えて、/etc/apt/apt.conf.d/
ディレクトリや /etc/apt/apt.conf
に指示文を書いたファイルを追加して APT の特定の機能を設定できます。たとえば、APT に dpkg
がファイルの衝突によるエラーを無視するよう設定するには、DPkg::options { "--force-overwrite"; }
のように書きます。
ウェブにアクセスするには必ずプロキシを介す必要がある場合、
Acquire::http::proxy "http://yourproxy:3128"
の行を追加してください。FTP プロキシは
Acquire::ftp::proxy "ftp://yourproxy"
のように追加してください。より多くの設定オプションを確認するには、
apt.conf(5) マニュアルページをご覧ください (マニュアルページの詳細は
第 7.1.1 節「マニュアルページ」をご覧ください)。
APT の設定で最も重要な側面の 1 つに各パッケージソースに対する優先度の管理があります。たとえば、テスト版、不安定版、実験版から入手できる新しいパッケージを 1 つか 2 つあるディストリビューションにインストールしたいと思うかもしれません。利用できるパッケージに対してそれぞれ別の優先度を割り当てることが可能です (同じパッケージに対してバージョンやそれを提供しているディストリビューションに依存する異なる優先度を設定することも可能です)。優先度の設定は APT の挙動に影響をおよぼします。すなわち、各パッケージについて、APT は常に最も優先度の高いバージョンをインストールします (例外は、最も優先度の高いバージョンがインストール済みのバージョンよりも古い場合か 1000 より低い優先度を持っている場合です)。
APT はいくつかのデフォルト優先度を定義しています。インストール済みパッケージのバージョンは優先度 100 です。インストールされていないパッケージのバージョンはデフォルトで優先度 500 ですが、ターゲットリリース (-t
コマンドラインオプションか APT::Default-Release
の設定指示文によって定義します) に含まれるバージョンの場合、優先度 990 になります。
優先度を変更するには、/etc/apt/preferences.d
または /etc/apt/preferences
ファイルに、影響を受けるパッケージの名前、バージョン、パッケージの提供者、新しい優先度を指定するエントリを追加してください。
APT は優先度が 1000 より高い場合 ( あるいはユーザの要求に従っている場合、参照:
第 6.2.2 節「インストールと削除」) を除いて、パッケージの古いバージョン (言い換えれば、現在インストールされているバージョンよりバージョン番号が低いパッケージ) をインストールしません。APT は常にこの制限に基づいて最も高い優先度のパッケージをインストールします。2 つのバージョンが同じ優先度の場合、APT は最新の (バージョン番号が最も高い) バージョンをインストールします。バージョンと優先度が同じで、パッケージの内容が異なる場合、APT はインストールされていないバージョンをインストールします (このルールはあるパッケージがリビジョン番号を変化させずに更新された場合に対応させるために作られました。通常はリビジョン番号を増加させなければいけません)。
もっと具体的に言えば、あるパッケージの優先度は
- < 0
インストールされることはありません、
- 1..99
他のバージョンのパッケージがない場合に限りインストールされます、
- 100..499
他のバージョンのパッケージがなく、他のディストリビューションで配布されている場合に限りインストールされます、
- 500....989
他のバージョンのパッケージがないか、目的のディストリビューションの中に存在する場合、
- 990..1000
既存のバージョンより新しい場合にインストールされます、
- > 1000
常にインストールされます、APT がダウングレードの指示を出していても無視されます。
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, 12 for Debian Bookworm). Let's have a look at its syntax through some realistic case studies of this mechanism.
Debian の安定版バージョンに含まれるパッケージだけを使いたいと仮定します。安定版以外のバージョンに含まれるパッケージは、明示的に要求されない限り、インストールされるべきではありません。この場合、/etc/apt/preferences
ファイルに以下のエントリを書きます。
a=stable
の含まれるエントリはディストリビューションの名前が stable のパッケージの優先度を 900 にしています。o=Debian
の含まれるエントリは、自分よりも前に評価されたエントリにマッチしなかった、共有元が「Debian」のパッケージの優先度を -10 にしています。
Let's now assume that you have a server with several local programs depending on the version 5.32 of Perl and that you want to ensure that upgrades will not install another version of it. You could use this entry:
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
第 6.3.1 節「The apt-cache policy
Command」.
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
.
apt
は素晴らしいツールであり、他のディストリビューションに含まれるパッケージをインストールする際に力を発揮します。たとえば、安定版システムをインストールした後にテスト版や不安定版に含まれるソフトウェアのパッケージを試したいが、システムを最初の状態から大きく変更したくないという場合に力を発揮します。
パッケージごとに取得元ディストリビューションを変えていると、時々システムに問題が起きるかもしれませんが、
apt
はシステム内に複数のディストリビューションをうまく共存させ、危険のおよぶ範囲をうまく限定します。進むべき最善の道は、
/etc/apt/sources.list
に共存させるすべてのディストリビューションを書いて (常に 3 つのディストリビューションを書いている人もいますが、
不安定版は経験豊富なユーザ向けであることを忘れないでください)、
APT::Default-Release
パラメータで基準ディストリビューションを定義することです (
第 6.2.3 節「システムのアップグレード」を参照してください)。
安定版を基準ディストリビューションと仮定し、併せてテスト版と不安定版用のリポジトリも sources.list
ファイルに書かれていると仮定します。この場合、テスト版に含まれるパッケージをインストールするには apt install package/testing
を使います。依存関係の解決に失敗してインストールできなかった場合、-t testing
パラメータを付けてテスト版を使って依存関係を解決させることが可能です。不安定版でも同じことが言えます。
In this situation, upgrades (
upgrade
and
full-upgrade
) are done within
Stable except for packages already upgraded to another distribution: those will follow updates available in the other distributions. We will explain this behavior with the help of the default priorities set by APT below. Do not hesitate to use
apt-cache policy
(
第 6.3.1 節「The apt-cache policy
Command」) to verify the given priorities.
APT はインストール済みのパッケージに比べてバージョンが高いか同じのパッケージだけを考慮するという事実を知れば、すべてを理解できます (ここでは /etc/apt/preferences
の中に一部のパッケージに対して 1000 より高い優先度を強制する設定がないと仮定します)。
あるパッケージの、安定版に含まれるバージョン 1 がインストール済みで、テスト版と不安定版に含まれるバージョン 2 と 3 が利用できると仮定しましょう。インストール済みバージョンの優先度は 100 ですが、安定版に含まれるバージョン (インストール済みのバージョンと全く同じバージョン) の (ターゲットリリースに含まれるバージョンの) 優先度は 990 です。テスト版と不安定版に含まれるバージョンの優先度 (インストールされていないバージョンに対するデフォルト優先度) は 500 です。この場合、インストール済みのバージョン 1 が最も高い優先度 990 を持ちます。パッケージは「安定版のまま」です。
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 the version in 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. 自動的にインストールされたパッケージの追跡
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.
あるパッケージを削除する際に、パッケージマネージャは、この追跡情報を元に、既に不要となった自動パッケージを選び出すことができます (なぜなら、依存関係によってインストールされたパッケージのうち、「手作業でインストール」されていないパッケージは不要と判断できるからです)。不要になった自動パッケージを削除するには apt-get autoremove
または apt autoremove
を使います。aptitude
にはこのコマンドがありません。なぜなら aptitude
は不要な自動パッケージを見つけ次第自動的に削除するからです。どのプログラムを使った場合も、不要になった自動パッケージは分かりやすく表示されます。
直接的に使うわけではないパッケージを自動パッケージとしてマークするのは良い癖です。こうすれば、そのパッケージがいらなくなった時に自動的に削除されます。
apt-mark auto package
はパッケージを自動パッケージとしてマークし、逆に
apt-mark manual package
は手動パッケージとしてマークします。
aptitude markauto
と
aptitude unmarkauto
は同様に動きますが、多くのパッケージを同時にマークする機能を持っています (
第 6.5.1 節「aptitude
」を参照してください)。
aptitude
のコンソールベース対話型インターフェースを使うと、多くのパッケージの「自動パッケージフラグ」を容易に確認できます。
自動的にインストールされたパッケージがシステムに存在する理由を知りたい場合があるかもしれません。この情報をコマンドラインから得るには、aptitude why package
を使ってください (apt
および apt-get
に同様の機能はありません)。
$
aptitude why python3-debian
i python3-reportbug Depends python3-debian
Patterns allow you to specify complex search queries to select the packages you want to install or show. They were first implemented for aptitude (see
第 6.5 節「フロントエンド、aptitude
、synaptic
」), but now APT can also make use of them.
For example, we can use apt list ?automatic
to list all the packages automatically installed. To find packages automatically installed no longer depended upon by manually installed packages the pattern ?garbage
can be used.
Logic patterns can be combined with other packages to form more complex expressions. For instance, we could use a pattern like ?and(PATTERN, PATTERN)
. See apt-patterns(7) and glob(7) for all the patterns you can use and the complex expressions you can create with them.