第2章 Debian パッケージ管理

目次

2.1. Debian パッケージ管理の前提条件
2.1.1. Debian package management system
2.1.2. パッケージ設定
2.1.3. 基本的な注意事項
2.1.4. 永遠のアップグレード人生
2.1.5. Debian アーカイブの基本
2.1.6. Debian は 100% フリーソフトウェアーです
2.1.7. パッケージ依存関係
2.1.8. パッケージ管理のイベントの流れ
2.1.9. パッケージ管理のトラブルへの応急対処法
2.1.10. Debian パッケージの選択方法
2.1.11. How to cope with conflictig requirements
2.2. 基本的パッケージ管理操作
2.2.1. aptapt-get/apt-cacheaptitude の比較
2.2.2. コマンドラインによる基本的なパッケージ管理操作
2.2.3. aptitude のインタラクティブな使用
2.2.4. aptitude のキーバインディング
2.2.5. aptitude の下でのパッケージの表示
2.2.6. aptitude を使った探索方法
2.2.7. aptitude の regex 式
2.2.8. aptitude による依存関係の解決
2.2.9. パッケージアクティビティーログ
2.3. aptitude 操作例
2.3.1. Seeking interesting packages
2.3.2. regex にマッチするパッケージ名のパッケージをリスト
2.3.3. regex マッチをしての閲覧
2.3.4. パッケージの完全削除
2.3.5. 自動 / 手動インストール状態の整理
2.3.6. システム全体のアップグレード
2.4. 高度なパッケージ管理操作
2.4.1. コマンドラインによる高度なパッケージ管理操作
2.4.2. インストールされたパッケージファイルの検証
2.4.3. パッケージ問題からの防御
2.4.4. パッケージメタデーターの検索
2.5. Debian パッケージ管理の内部
2.5.1. アーカイブのメタデーター
2.5.2. トップレベルの "Release" ファイルと信憑性
2.5.3. アーカイブレベルの "Release" ファイル
2.5.4. パッケージメタデーターの取得
2.5.5. APT に関するパッケージ状態
2.5.6. aptitude に関するパッケージ状態
2.5.7. 取得したパッケージのローカルコピー
2.5.8. Debian パッケージファイル名
2.5.9. dpkg コマンド
2.5.10. update-alternative コマンド
2.5.11. dpkg-statoverride コマンド
2.5.12. dpkg-divert コマンド
2.6. 壊れたシステムからの復元
2.6.1. Failed installation due to missing dependencies
2.6.2. Caching errors of the package data
2.6.3. 古いユーザーの設定との非互換性
2.6.4. 重複するファイルを持つ相異なるパッケージ
2.6.5. 壊れたパッケージスクリプトの修正
2.6.6. dpkg コマンドを使っての救済
2.6.7. パッケージセレクションの復元
2.7. パッケージ管理のヒント
2.7.1. 誰がパッケージをアップロードしたのか?
2.7.2. APT のよるダウンロードバンド幅の制限
2.7.3. パッケージの自動ダウンロードとアップグレード
2.7.4. Updates と Backports
2.7.5. External package archives
2.7.6. Packages from mixed source of archives without apt-pinning
2.7.7. Tweaking candidate version with apt-pinning
2.7.8. "推奨 (Recommends)" によりパッケージがインストールされるのを阻止
2.7.9. unstable からのパッケージと共に、testing を追いかける
2.7.10. experimental からのパッケージと共に、unstable を追いかける
2.7.11. 緊急ダウングレード
2.7.12. equivs パッケージ
2.7.13. 安定版システムへのパッケージ移植
2.7.14. APT のためのプロキシサーバー
2.7.15. パッケージ管理の追加参考文書
[注記] 注記

本章は最新安定版リリースがコード名: bookworm と言う前提で書かれています。

The data source of the APT system is collectively reffered as the source list in this document . This can be defined anywhere in the "/etc/apt/sources.list" file, "/etc/apt/sources.list.d/*.list" files, or "/etc/apt/sources.list.d/*.source" files.

Debian は、フリーソフトウエアーのコンパイル済みバイナリーパッケージからなる整合性あるディストリビューションを作り、そのアーカイブを通じてそれらを頒布するボランティア組織です。

Debian のアーカイブは、HTTP や FTP 法によるアクセスされるための多くのリモートのミラーサイトとして提供されています。それは、CD-ROM/DVD によっても提供されています。

The current Debian package management system which can utilize all these resources is Advanced Packaging Tool (APT).

Debian のパッケージ管理システムは、適正に使われればバイナリーパッケージの整合性ある組み合わせがアーカイブからシステムにインストールされるようになっています。現在、amd64 アーキテクチャーでは 70081 つのパッケージが利用できます。

Debian のパッケージ管理システムは、多彩な歴史があり、使用されるフロントエンドのユーザープログラムやバックエンドのアーカイブへのアクセス方法に多くの選択肢があります。現在は以下を推薦します。

  • パッケージのインストール・削除や dist-upgrade を含む全ての対話的コマンドライン操作を提供する、apt(8)。

  • スクリプトから Debian のパッケージ管理をするためによぶ、apt-get(8)。(古い Debian システム等で)apt が使えない際の控えのオプション。

  • インストールされたパッケージを管理したり、使用可能なパッケージを探索するためのインタラクティブなテキストインターフェースを提供する、aptitude(8)


[警告] 警告

ランダムな混合のスイーツからパッケージをインストールしてはいけません。コンパイラーの ABI とかライブラリー のバージョンとかインタープリターの機能等のシステム管理に関する深い知見が必要なパッケージの整合性がきっと破壊されます。

The newbie Debian system administrator should stay with the stable release of Debian while applying only security updates. Until you understand the Debian system very well, you should follow the following precautions.

  • Do not include testing or unstable in the source list.

  • Do not mix standard Debian with other non-Debian archives such as Ubuntu in the source list .

  • "/etc/apt/preferences" を作成しません。

  • パッケージ管理ツールのデフォールトを影響を理解せずに変更しません。

  • ランダムなパッケージを "dpkg -i random_package" でインストールしません。

  • ランダムなパッケージを "dpkg --force-all -i random_package" で絶対インストールしません。

  • "/var/lib/dpkg/" の中のファイルを消去や改変しません。

  • ソースから直接コンパイルしたソフトウエアープログラムをインストールする際にシステムファイルを上書きしません。

    • 必要な場合は "/usr/local/" か "/opt/" 中にインストールします。

The non-compatible effects caused by violating above precautions to the Debian package management system may leave your system unusable.

ミッションクリティカルなサーバーを走らせる真剣な Debian システム管理者は更なる用心をすべきです。

  • 安全な条件下であなたの特定の設定で徹底的にテストすることなくセキュリティーアップデートをも含めた如何なるパッケージもインストールをしてはいけません。

    • システム管理者のあなたがシステムに対して最終責任があります。

    • Debian システムの長い安定性の歴史それ自体は何の保証でもありません。

[注意] 注意

あなたの業務サーバーには、セキュリティーアップデートをした安定版 stable スイーツを推薦します。管理に限られた時間しか割けないデスクトップ PC に関しても同様の事が言えます。

Despite my warnings above, I know many readers of this document may wish to run the newer testing or unstable suites.

以下に記すことにより悟りを開けば、アップグレード地獄という果てしない因果応報の葛藤から人は解脱し、Debian の涅槃の境地に到達できます。

This list is targeted for the self-administered Desktop environment.

  • Use the testing suite since it is practically the rolling release automatically managed by the Debian archive QA infrastructure such as the Debian continuous integration, the source only upload practices, and the library transition tracking. The packages in the testing suite are updated frequently enough to offer all the latest features.

  • Set the codename corresponding to the testing suite ("trixie" during the bookworm-as-stable release cycle) in the source list.

  • Manually update this codename in the source list to the new one only after assessing situation by yourself for about a month after the major suite release. The Debian user and developer mailing list are good sources of information for this, too.

The use of the unstable suite isn't recommended. The unstable suite is good for debugging packages as a developer but tends to expose you to unnecessary risks for the normal Desktop usage. Even though the unstable suite of the Debian system looks very stable for most of the times, there have been some package problems and a few of them were not so trivial to resolve.

Here are some basic precautionary measure ideas to ensure quick and easy recovery from bugs in Debian packages.

  • Debian システムの安定版 stable スイーツを別のパーティションにインストールし、システムをヂュアルブータブル

  • レスキューブートのためのインストール用 CD を手元に確保

  • apt-listbugs をインストールしてアップグレードの前に Debian バグトラッキングシステム (BTS) をチェックを考慮

  • 問題回避するのに十分なだけのパッケージシステムの基盤を学習

[注意] 注意

If you can not do any one of these precautionary actions, you are probably not ready for the testing and unstable suites.

[ヒント] ヒント

Debian アーカイブの正式のポリシーは Debian ポリシーマニュアル、第2章 - Debian アーカイブに規定されています。

Debian アーカイブをシステムユーザーの視点から見てみます。

For a system user, the Debian archive is accessed using the APT system.

The APT system specifies its data source as the source list and it is described in sources.list(5).

For the bookworm system with the typical HTTP access, the source list in one-line-style as the following:

deb http://deb.debian.org/debian/ bookworm main non-free-firmware contrib non-free
deb-src http://deb.debian.org/debian/ bookworm main non-free-firmware contrib non-free

deb http://security.debian.org/debian-security bookworm-security main non-free-firmware contrib non-free
deb-src http://security.debian.org/debian-security bookworm-security main non-free-firmware contrib non-free

Alternatively, the equivqlent source list in deb822-style as the following.

Types: deb deb-src
URIs: http://deb.debian.org/debian/
Suites: bookworm
Components: main non-free-firmware contrib non-free

Types: deb deb-src
URIs: http://security.debian.org/debian-security/
Suites: bookworm-security
Components: main non-free-firmware contrib non-free

Key points of the source list are followings.

  • One-line-style format

    • It's definition files are in the "/etc/apt/sources.list" file and "/etc/apt/sources.list.d/*.list" files.

    • Each line defines the data source for the APT system.

    • "deb" 行がバイナリーパッケージのための定義です。

    • "deb-src" 行がソースパッケージのための定義です。

    • 一番目の引数は、Debian アーカイブの root URL です。

    • The 2nd argument is the distribution name using either the suite name or the codename.

    • 三番目次の引数は、Debian アーカイブの中の有効なアーカイブのエリア名のリストです。

  • Deb822-style format

    • It's definition files are in "/etc/apt/sources.list.d/*.source" files.

    • Each block of lines separated by a blank line defines the data source for the APT system.

    • The "Types:" stanza defines the list of types such as "deb" and "deb-src".

    • The "URIs:" stanza defines the list of root URIs of the Debian archive.

    • The "Suites:" stanza defines the list of distribution names using either the suite name or the codename.

    • The "Components:" stanza defines the list of valid archive area names of the Debian archive.

The definition for "deb-src" can safely be omitted if it is just for aptitude which does not access source related meta data. It speeds up the updates of the archive meta data.

The URL can be "http://", "ftp://", "file://", ….

Lines starting with "#" are comments and ignored.

Here, I tend to use codename "bookworm" or "trixie" instead of suite name "stable" or "testing" to avoid surprises when the next stable is released.

[ヒント] ヒント

If "sid" is used in the above example instead of "bookworm", the "deb: http://security.debian.org/ …" line or its deb822 equivalent content for security updates in the source list is not required. This is because there is no security update archive for "sid" (unstable).

Here is the list of URL of the Debian archive sites and suite name or codename used in the configuration file after the bookworm release.


[注意] 注意

Only pure stable release with security updates provides the best stability. Running mostly stable release mixed with some packages from testing or unstable release is riskier than running pure unstable release for library version mismatch etc. If you really need the latest version of some programs under stable release, please use packages from stable-updates and http://backports.debian.org (see 「Updates と Backports」) services. These services must be used with extra care.

[注意] 注意

基本的に、stabletestingunstable のスイーツの内の1つだけを "deb" 行に書くべきです。もし、stabletestingunstable のスイーツの何らかの組み合わせを "deb" 行に書けば、APT プログラムは、最新のアーカイブのみが有効であるにもかかわらず、実行速度が低下します。"/etc/apt/preferences" ファイルがはっきりとした目的を持って使われている場合 (「Tweaking candidate version with apt-pinning) のみ複数のリストに意味があります。

[ヒント] ヒント

For the Debian system with the stable suite, it is a good idea to include the content with "http://security.debian.org/" in the source list to enable security updates as in the example above.

[注記] 注記

stable アーカイブのセキュリティーバグは Debian のセキュリティーチームにより修正されます。本活動は非常に厳格で信頼できるものです。testing アーカイブのセキュリティーバグは Debian の testing セキュリティーチームにより修正されます。諸所の 事情で、本活動は stable ほどは厳格ではなく、修正された unstable パッケージの移行を待つ必要があるかもしれません。unstable アーカイブのセキュリティーバグは個別のメンテナにより修正されます。活発にメンテされている unstable パッケージはアップストリームのセキュリティー修正を使うことで通常比較的良い状態です。Debian がセキュリティーバグへ如何に対応するかに関しては Debian security FAQ を参照下さい。


ここで、上記にあるパッケージ数は amd64 アーキテクチャーに関する数字です。main エリアのアーカイブのみが Debian システムです(「Debian は 100% フリーソフトウェアーです」参照)。

Debian アーカイブの構成は、各アーカイブの URL の後ろに distspool をつけた URL にブラウザーを向ければ学習できます。

ディストリビューションは、スイーツとコード名の2つの方法で言及されます。この他にディストリビューションと言う言葉は多くの文書でスイーツの同義語としても使われています。スイーツとコード名の関係は次のようにまとめられます。


コード名の歴史は、Debian FAQ: 6.2.1 Which other codenames have been used in the past? に記載されています。

比較的厳格な Debian アーカイブの用語法では、"セクション" という言葉はアプリケーションの分野によるパッケージ分類に特化して使われます。(しかし、"main セクション" という言葉は main エリアを提供する Debian アーカイブ部分を表現するのにしばしば使われています。)

Debian デベロッパー (DD) が不安定版 unstable アーカイブに新たなアップロードを (incoming での処理を経由して) する度毎に、アップロードするパッケージが最新の不安定版 unstable アーカイブの最新のパッケージ集合とコンパチブルであるようにする義務が DD にはあります。

重要なライブラリーのアップグレード他の理由で DD がこのコンパチビリティーを壊す際には、debian-devel のメーリングリスト他に通常アナウンスがされます。

Debian のアーカイブ管理スクリプトによって非安定版 unstable アーカイブからテスト版 testing アーカイブへパッケージ集合が移動される前に、アーカイブ管理スクリプトはパッケージの成熟度 (約10日経過) と RC バグレポート状況を確認するばかりでなく、テスト版 testing アーカイブの最新パッケージ集合とのコンパチブルであるようにするように努めます。このプロセスがあるので、テスト版 testing アーカイブは非常に新しくかつ使いやすいのです。

リリースチームによる徐々のアーカイブ凍結過程を通じて、少々の手動の介入を伴いつつテスト版 testing アーカイブは完全に整合性をもったバグの無い状態へと徐々に熟成されます。そして、古いテスト版 testing アーカイブのコード名を新たな安定版 stable アーカイブへと割り当て、新たなコード名を新たなテスト版 testing アーカイブへと割り当てることで、新たな安定版 stable がリリースされます。新たなテスト版 testing アーカイブの当初の内容は、新たにリリースされた安定版 stable アーカイブとまったく同じです。

不安定版 unstable もテスト版 testing アーカイブもともにいくつかの要因で一時的に細かな問題発生があるかもしれません。

  • ブロークンなパッケージのアーカイブへのアップロード (主に unstable にて)

  • 新規パッケージをアーカイブに受け入れる際の遅延 (主に unstable にて)

  • アーカイブの同期のタイミング問題 (testingunstable の両方にて)。

  • パッケージの除去などのアーカイブへの手動の介入 (どちらかといえば testing にて)、等。

もしこれらのアーカイブを使おうと考えるなら、この種の細かな問題の修復や回避は必須技能です。

[注意] 注意

たとえいつも非安定版 unstable やテスト版 testing アーカイブを使っていようとも、ほとんどのデスクトップユーザーは新たな安定版 stable リリースの後約数ヶ月はセキュリティーアップデートされた安定版 stable アーカイブを使うべきです。この移行期は、非安定版 unstable もテスト版 testing アーカイブの何れももほとんどの人に良いものではありません。非安定版 unstable アーカイブを使おうとすると、核となるパッケージが大アップグレードの嵐に見舞われるので、あなたのシステムをうまく使える状態に保つのは困難です。テスト版 testing アーカイブを使おうとしても、安定版 stable アーカイブとほとんど同じ内容でセキュリティーサポートはありません (Debian testing-security-announce 2008-12)。1ヶ月ほど経てば、非安定版 unstable アーカイブなら注意を払えば使えるかもしれません。

[ヒント] ヒント

テスト版 testing アーカイブを追跡している際には、除去されたパッケージによって引き起こされる問題は該当するバグ修正のためにアップロードされたパッケージを非安定版 unstable アーカイブからインストールすれば通常回避できます。

アーカイブの定義は、Debian ポリシーマニュアルを参照下さい。

Debian は以下の理由で 100% フリーソフトウエアーです:

  • Debian はユーザーの自由を尊重すべくデフォルトではフリーソフトウェアのみをインストールします。

  • Debian は main 中にはフリーソフトウエアーのみを提供します。

  • Debian は main からのフリーソフトウエアーのみを実行することを推奨します。

  • No packages in main depend nor recommend packages in non-free nor non-free-firmware nor contrib.

一部の人は以下の2つの事実が矛盾するのでは無いかとの疑問を持ちます。

これらは以下の理由で矛盾しません。

  • Debian システムは 100% フリーソフトウエアーでそのパッケージは Debian サーバーの main エリア中にホストされます。

  • Packages outside of the Debian system are hosted by Debian servers in the non-free, non-free-firmware and contrib areas.

これらは Debian 社会契約の第4項と第5項中に正確に説明されています:

  • 私たちはユーザーとフリーソフトウェアーを大切にします

    • 私たちはユーザーとフリーソフトウェアーコミュニティーからの要求に従います。 彼らの関心を最優先に考えます。 私たちはさまざまな状況におけるコンピューター利用環境の運用に関して、 ユーザーの必要を満たすように行動します。私たちは Debian システム上での利用を目的としたフリーではない著作物に敵対することはありません。 またそのような著作物を作成または利用する人々に対して、料金を徴収することはありません。 私たちは、Debian システムとその他の著作物の両方を含むディストリビューションを、 第三者が作成することも認めています。その際、私たちは料金を徴収しません。 私たちはこれらの目標を増進させるために、 これらのシステムの使用を妨げるような法的な制約のない、 高品質な素材を統合したシステムを提供します。

  • 私たちのフリーソフトウェアー基準に合致しない著作物について

    • We acknowledge that some of our users require the use of works that do not conform to the Debian Free Software Guidelines. We have created "non-free", "non-free-firmware" and "contrib" areas in our archive for these works. The packages in these areas are not part of the Debian system, although they have been configured for use with Debian. We encourage CD manufacturers to read the licenses of the packages in these areas and determine if they can distribute the packages on their CDs. Thus, although non-free works are not a part of Debian, we support their use and provide infrastructure for non-free packages (such as our bug tracking system and mailing lists). The Debian official media may include firmware that is otherwise not part of the Debian system to enable use of Debian with hardware that requires such firmware.

[注記] 注記

The actual text of the 5th term in the current Debian Social Contract 1.2 is slightly different from the above text. This editorial deviation is intensional one to make this user document consistent without changing the real content of the Social Contract.

Users should be aware of the risks of using packages in the non-free, non-free-firmware and contrib areas:

  • そのようなソフトウエアーパッケージに関する自由の欠如

  • そのようなソフトウエアーパッケージに関するDebianからのサポートの欠如 (Debian はソフトウエアーのソースコードに適切なアクセスなしにはソフトウエアーをサポートできません。)

  • あなたの 100% フリーソフトウエアーの Debain システムへの汚染

Debian フリーソフトウェアーガイドラインDebian のフリーソフトウエアー基準です。Debian は「ソフトウエアー」に関して、パッケージ中の文書、ファームウエアー、ロゴ、アート作品を含む最も広義の解釈をします。このことにより Debian のフリーソフトウエアー基準は非常に厳格なものとなります。

Typical non-free, non-free-firmware and contrib packages include freely distributable packages of following types:

Please note that the number of non-free, non-free-firmware and contrib packages is less than 2% of that of main packages. Enabling access to the non-free, non-free-firmware and contrib areas does not obscure the source of packages. Interactive full screen use of aptitude(8) provides you with full visibility and control over what packages are installed from which area to keep your system as free as you wish.

Debian システムはコントロールファイル中のバージョン情報付きのバイナリー依存関係宣言を通して整合性のあるバイナリーパッケージの集合を提供します。ここにその少々簡素化し過ぎの定義を示します。

  • "Depends"

    • これは絶対依存を宣言し、このフィールドにリストされた全てのパッケージは同時または事前にインストールされていなければいけません。

  • "Pre-Depends"

    • これは、リストされたパッケージが事前にインストールを完了している必要がある以外は、Depends と同様です。

  • "Recommends"

    • これは強いが絶対でない依存を宣言します。多くのユーザーはこのフィールドにリストされたパッケージ全てがインストールされていなければ、当該パッケージを望まないでしょう。

  • "Suggests"

    • これは弱い依存を宣言します。このパッケージの多くのユーザーはこのフィールドにリストされたパッケージをインストールすればメリットを享受できるとは言え、それら抜きでも十分な機能が得られます。

  • "Enhances"

    • This declares a weak dependency like Suggests but works in the opposite direction.

  • "Breaks"

    • これは通常バージョン制約付きでパッケージのインコンパチビリティーを宣言します。一般的にこのフィールドにリストされた全てのパッケージをアップグレードすることで解決します。

  • "Conflicts"

    • これは絶対的排他関係を宣言します。このフィールドにリストされた全てのパッケージを除去しない限り当該パッケージをインストールできません。

  • "Replaces"

    • 当該パッケージによりインストールされるファイルがこのフィールドにリストされたパッケージのファイルを置き換える際にこれを宣言します。

  • "Provides"

    • 当該パッケージがこのフィールドにリストされたパッケージのファイルと機能の全てを提供する際にこれを宣言します。

[注記] 注記

正常な設定として "Provides" と "Conflicts" と "Replaces" とを単一バーチャルパッケージに対し同時宣言することがあります。こうするといかなる時にも当該バーチャルパッケージを提供する実パッケージのうち確実に一つだけがインストールされます。

ソースの依存関係をも含む正式の定義は the Policy Manual: Chapter 7 - Declaring relationships between packages にあります。

パッケージ管理の簡略化されたイベントの流れをまとめると次のようになります。

上記では全体像の理解のためにわざと技術詳細を端折っています。

内容が正確な正式文書を読むように心がけるべきです。まず Debian に特定のことが記載された "/usr/share/doc/package_name/README.Debian" を最初に読むべきです。また "/usr/share/doc/package_name/" の中にある他の文書も参照すべきです。「Bash のカスタム化」に書かれたようなシェル設定がされていれば、次のようにタイプして下さい。

$ cd package_name
$ pager README.Debian
$ mc

さらに詳しい情報を得るには "-doc" というサフィクスを持った対応する文書パッケージをインストールする必要があるかもしれません。

特定パッケージに関する問題に出会った際には、Debian バグトラッキングシステム (BTS) サイトを必ず確認します。


"site:debian.org" や "site:wiki.debian.org" や "site:lists.debian.org" 等を含む検索語で Google を検索します。

バグ報告をする際には、reportbug(1) コマンドを使います。

Whatever suite of Debian system you may decide to use, you may still wish to run versions of programs which aren't available in that suite. Even if you find binary packages of such programs in other Debian suites or in other non-Debian resources, their requirements may conflict with your current Debian syetem.

Although you can tweak package management system with apt-pinning technique etc. as described in 「Tweaking candidate version with apt-pinning to instal such out-of-sync binary packages, such tweaking approaches have only limited use cases since they may break those programs and your system.

Before brutally installing such out-of-sync packages, you should seek all available alternative safer technical solutions which are compatible with your current Debian syetem.

Debian システム上でのレポジトリーを使ったパッケージ管理操作は Debian システム上にある多くのAPTを使うパッケージ管理ツールを使いできます。ここでは、apt /apt-get / apt-cacheaptitude といった3つの基本的なパッケージ管理ツールを説明します。

パッケージをインストールしたりパッケージのメタデーターを更新するようなパッケージ管理操作には root 権限が必要です。

aptitude は筆者が主に使う非常に良いインタラクティブツールではありますが、注意すべき事実があることを知っておくべきです。

apt-getapt-cache コマンドはAPTを使う最も基本的なパッケージ管理ツールです。

  • apt-get/apt-cache はコマンドラインのユーザーインターフェースのみを提供します。

  • apt-get はリリース間のような大掛かりなシステムアップグレードに最適です。

  • apt-get頑強で安定なパッケージリゾルバーを提供します。

  • apt-getはハードウエアリソースへの要求が楽である。メモリーの消費は少なく、実行速度が早い。

  • apt-cache はパッケージ名や説明に関して標準の regex を使った検索機能を提供します。

  • apt-getapt-cache/etc/apt/preferences を使って複数のバージョンのパッケージを管理できますが、それはとても面倒です。

apt コマンドはパッケージ管理のための上位コマンドラインインターフェースです。基本的に apt-getapt-cache 等のコマンドのラッパーで、インタラクティブな用途に良いオプションをデフォルトで有効にしてエンドユーザーインターフェース向けとなっています。

  • apt は、apt install としてパッケージをインストールするとフレンドリーなプログレスバーを提供します。

  • apt は、ダウンロードされたパッケージが上手くインストールされた後、デフォルトでキャッシュされた .deb パッケージを削除 します。

[ヒント] ヒント

ユーザーは インタラクティブ 用途には apt(8) コマンドを使うことが推奨されますし、シェルスクリプト中ではapt-get(8) や apt-cache(8) コマンドを使うことが推奨されます。

aptitude コマンドは最も多芸なAPTを使うパッケージ管理ツールです。

  • aptitude はフルスクリーンのインタラクティブなテキストユーザーインターフェースを提供します。

  • aptitude はコマンドラインのユーザーインターフェースも提供します。

  • aptitude はインストールされたパッケージを検査したり利用可能なパッケージを探索したりするような日常のインタラクティブなパッケージ管理に最適です。

  • aptitudeはハードウエアリソースへの要求が厳しい。メモリーの消費は多く、実行速度も遅い。

  • aptitude はパッケージメタデータ全てに関する拡張されたregex を使った探索を提供します。

  • aptitude/etc/apt/preferences を使わずに複数のバージョンのパッケージを管理できますし、それは非常に直感的です。

apt(8) や aptitude(8) や apt-get(8) /apt-cache(8) を使うコマンドラインによるパッケージ管理操作を次に記します。

表2.6 apt(8) や aptitude(8) や apt-get(8) /apt-cache(8) を使うコマンドラインによる基本パッケージ管理操作

apt シンタックス aptitude シンタックス apt-get/apt-cache シンタックス 説明
apt update aptitude update apt-get update パッケージアーカイブメタデーター更新
apt install foo aptitude install foo apt-get install foo "foo" パッケージの候補バージョンをその依存関係とともにインストール
apt upgrade aptitude safe-upgrade apt-get upgrade 他のパッケージを削除すること無くインストール済みパッケージの候補バージョンをインストール
apt full-upgrade aptitude full-upgrade apt-get dist-upgrade 必要なら他のパッケージを削除しながらインストール済みパッケージの候補バージョンをインストール
apt remove foo aptitude remove foo apt-get remove foo 設定ファイルを残したまま "foo" パッケージを削除
apt autoremove N/A apt-get autoremove 既に必要なくなっている自動済みパッケージを削除
apt purge foo aptitude purge foo apt-get purge foo 設定ファイルを含めて "foo" パッケージを完全削除
apt clean aptitude clean apt-get clean 収集されローカルに貯蔵されたパッケージファイルを完全消去
apt autoclean aptitude autoclean apt-get autoclean 収集されローカルに貯蔵されたパッケージファイルのうち古くなったパッケージを消去
apt show foo aptitude show foo apt-cache show foo "foo"パッケージに関する詳細情報を表示
apt search regex aptitude search regex apt-cache search regex regex とマッチするパッケージを検索
N/A aptitude why regex N/A なぜ regex とマッチするパッケージがインストールされるのかを説明
N/A aptitude why-not regex N/A なぜ regex とマッチするパッケージがインストールされないのかを説明
N/A aptitude search '~i!~M' apt-mark showmanual 手動インストールされたパッケージをリスト

apt / apt-get and aptitude can be mixed without major troubles.

"aptitude why regex" は "aptitude -v why regex" とすることで、さらに詳しい情報を表示します。同様の情報は "apt rdepends package" や "apt-cache rdepends package" とすることでも得られます。

aptitude コマンドが最初コマンドラインモードで実行されパッケージ間のコンフリクトのような問題に直面した場合は、プロンプトがでた際に "e" を押すことでフルスクリーンのインタラクティブモードに切り替えられます。

[注記] 注記

aptitude コマンドはその拡張されたパッケージリゾルバーのような豊富なフィーチャーとともに提供されますが、この複雑さは Bug #411123Bug #514930Bug #570377 のようないくつかのリグレッションを引き起こしました (また起こしているかもしれません)。疑義のある場合には、aptitude コマンドに代えて aptapt-getapt-cache コマンドを使ってください。

"aptitude" のすぐ後ろにコマンドオプションをつけられます。


詳細は aptitude(8) や "/usr/share/doc/aptitude/README" にある "aptitude user's manual" を参照下さい。

パッケージの状態を閲覧し、"予定のアクション" の設定をこのフルスクリーンモードで各パッケージするための重要なキーを次に記します。


The file name specification of the command line and the menu prompt after pressing "l" and "//" take the aptitude regex as described below. Aptitude regex can explicitly match a package name using a string started by "~n" and followed by the package name.

[ヒント] ヒント

ビジュアルインターフェースで全てのインストール済みパッケージを候補バージョンにアップグレードさせるには "U" を押さなければいけません。これをしないと選ばれたパッケージとそれにバージョン付きの依存関係のある特定のパッケージのみがアップグレードされます。

インタラクティブなフルスクリーンモードの aptitude(8) はパッケージリスト中のパッケージは次の例のように表示されます。

idA   libsmbclient                             -2220kB 3.0.25a-1  3.0.25a-2

上記の行は左から次に記すような意味です。

  • "現状" フラグ (1番目の文字)

  • "予定のアクション" フラグ (2番目の文字)

  • "自動" フラグ (3番目の文字)

  • パッケージ名

  • "予定のアクション" に帰属されるディスク空間の使用の変化

  • パッケージの現バージョン

  • パッケージの候補バージョン

[ヒント] ヒント

"?" を押して表示されるヘルプスクリーンの一番下に全フラグのリストがあります。

現在のローカルの環境設定によって候補バージョンは選ばれます (apt_preferences(5) と「Tweaking candidate version with apt-pinningを参照下さい)。

"表示" メニューの下にある数種のパッケージ表示が利用できます。


標準 "パッケージ画面" はパッケージを dselect にいくつかの機能を加えた感じで分類します。


[ヒント] ヒント

Tasks ビューはあなたのタスクに使うパッケージをいいとこ取りするのに使えます。

aptitude の regex 式は mutt 的な拡張 ERE (「正規表現」参照下さい) で aptitude に特定なマッチ規則の拡張は次に示すとおりです。

表2.11 aptitude の regex 式のリスト

拡張マッチ規則の説明 regex 式
パッケージ名とのマッチ ~n名前のregex
記述とのマッチ ~d記述のregex
タスク名とのマッチ ~tタスクのregex
debtag とのマッチ ~Gdebtagのregex
メンテナとのマッチ ~mmaintainerのregex
パッケージセクションとのマッチ ~sセクションのregex
パッケージバージョンとのマッチ ~Vバージョンのregex
アーカイブ (archive) とのマッチ ~A{bookworm,trixie,sid}
オリジン (origin) とのマッチ ~O{debian,…}
優先度 (priority) とのマッチ ~p{extra,important,optional,required,standard}
必須 (essential) パッケージとのマッチ ~E
仮想パッケージとのマッチ ~v
新規パッケージとのマッチ ~N
次のアクションとのマッチ ~a{install,upgrade,downgrade,remove,purge,hold,keep}
インストール済みパッケージとのマッチ ~i
A-マークのついたインストール済みパッケージとマッチ (自動インストール済みパッケージ) ~M
A-マークのついていないインストール済みパッケージとマッチ (管理者が選択したパッケージ) ~i!~M
インストール済みかつアップグレード可能なパッケージとマッチ ~U
削除済みだが完全削除されていないパッケージとマッチ ~c
削除済みか完全削除済みか削除可能なパッケージとマッチ ~g
壊れた依存関係宣言をしたパッケージとマッチ ~b
type の壊れた依存関係を宣言しているパッケージとマッチ ~Btype
type の壊れた依存関係を宣言している pattern パッケージとマッチ ~D[type:]pattern
type の壊れた依存関係を宣言している pattern パッケージとマッチ ~DB[type:]pattern
pattern マッチするパッケージが type の依存関係を宣言しているパッケージとマッチ ~R[type:]pattern
pattern マッチするパッケージが type の壊れた依存関係を宣言しているパッケージとマッチ ~RB[type:]pattern
他のインストール済みパッケージが依存するパッケージとマッチ ~R~i
他のインストール済みパッケージが一切依存しないパッケージとマッチ !~R~i
他のインストール済みパッケージが依存もしくは推薦するパッケージとマッチ ~R~i|~Rrecommends:~i
フィルターされたバージョンの pattern とマッチ ~S filter pattern
常に全てのパッケージにマッチ (真) ~T
どのパッケージにもマッチしない (偽) ~F

  • regex 部分は、"^" や ".*" や "$" などを使う egrep(1) や awk(1) や perl(1) といった典型的な Unix 的テキストツールで使われる ERE と同様です。

  • 依存関係を表す type はパッケージの相互関係を指定する (depends, predepends, recommends, suggests, conflicts, replaces, provides) の内の1つです。

  • デフォールトの依存関係は "depends" です。

[ヒント] ヒント

regex_pattern がヌル文字列の場合は "~T" をコマンドの直後に使って下さい。

次がショートカットです。

  • "~Pterm" == "~Dprovides:term"

  • "~Cterm" == "~Dconflicts:term"

  • "…~W term" == "(…|term)"

mutt が表現のお手本なので、mutt に慣れているユーザーはすぐ慣れるでしょう。"User's Manual" ("/usr/share/doc/aptitude/README") 中の "SEARCHING, LIMITING, AND EXPRESSIONS" を参照下さい。

[注記] 注記

lenny バージョンの aptitude(8) では、新規の "?broken" のような長形式の regex マッチ形式が、古い "~b" のような短形式のマッチ形式に代えて使えます。そのためチルダ文字 "~" に加えてスペース文字 " " も regex の終端文字として扱われます。新規の長形式のマッチ形式については "User's Manual" を参照下さい。

aptitude(8) 操作例を次に示します。

(非 aptitude のパッケージインストーラー等を使った後で) パッケージの自動 / 手動インストールの状態を整理する私の方法を次に記します。

  1. aptitude を root としてインタラクティブに起動します。

  2. "u" と "U" と "f" と "g" とタイプしてパッケージリストを更新しパッケージをアップグレードします。

  3. パッケージ表示制限を "~i(~R~i|~Rrecommends:~i)" と入力するために "l" とタイプし、自動インストールとなるよう "M" と "インストール済みのパッケージ" の上でタイプします。

  4. パッケージ表示制限を "~prequired|~pimportant|~pstandard|~E" と入力するために "l" とタイプし、手動インストールとなるよう "m" と "インストール済みのパッケージ" の上でタイプします。

  5. パッケージ表示制限を "~i!~M" と入力するために "l" とタイプし、"インストール済みのパッケージ" の上で "[" とタイプしてパッケージを見えるようにした後で個々のパッケージの上で "-" とタイプして使っていないパッケージを削除します。

  6. パッケージ表示制限を "~i" と入力するように "l" とタイプし、そして "タスク" の上で手動インストールとなるよう "m" とタイプします。

  7. aptitude を終了します。

  8. "apt-get -s autoremove|less" と root から起動して何が使われていないのか確認します。

  9. aptitude とインタラクティブモードで再起動して必要なパッケージを "m" でマークします。

  10. "apt-get -s autoremove|less" と root から再起動して削除対象が期待にかなっていることを再確認します。

  11. "apt-get autoremove|less" と root から起動して使用していないパッケージを自動削除します。

"Tasks" の上で "m" を押すのも一案で、大量ファイル除去となる事態が回避できます。

[注記] 注記

新規リリース等への移行は、Debian では下記のようにアップグレードできるのですが、新たなシステムをクリーンインストールすることを考えるべきです。こうすると溜めてきたゴミの除去ができる上に最新のパッケージの最良の組み合わせも分かります。もちろん安全な場所に完全なシステムのバックアップ (「バックアップと復元」参照下さい) を事前にしなくてはいけません。異なったパーティションを使ったデュアルブート設定をすることをスムーズな移行をするためにお薦めします。

You can perform system wide upgrade to a newer release by changing contents of the source list pointing to a new release and running the "apt update; apt dist-upgrade" command.

To upgrade from stable to testing or unstable during the bookworm-as-stable release cycle, you replace "bookworm" in the source list example of 「Debian アーカイブの基本」 with "trixie" or "sid".

一部のパッケージで移行に関して支障をきたすことが実際には起こるかもしれません。これは大体パッケージ依存関係に起因します。アップグレードする差が大きければ大きいほど比較的大きな問題似合う可能性がより大きくなります。以前の安定版 stable からリリース後の新規安定版 stable への移行では新規リリースノートを読んでそこに記載された手続き通りに完全にすれば問題発生を防げます。

安定版 stable からテスト版 testing へ移行すると決めた時には頼りにするリリースノートはありません。前回の安定版 stable のリリースの後で安定版 stable とテスト版 testing の差がかなり大きくなっているかもしれません。そうだとアップグレードをする状況は複雑になっています。

メーリングリストから最新情報を収集するとか常識を使うといった予防措置をしながらフルアップグレードをするべきです。

  1. 前回の "リリースノート" を読みます。

  2. 全システム (特にデーターや設定情報) をバックアップします。

  3. ブートローダーが壊れたときのためにブートできるメディアを確保します。

  4. システムを使っているユーザーに十分事前に通告します。

  5. script(1) を使ってアップグレード活動を記録します。

  6. 削除をされないように "aptitude unmarkauto vim" 等として、"unmarkauto" を重要なパッケージに適用します。

  7. デスクトップタスクにあるパッケージ等を削除して、インストールされたパッケージを減らしてパッケージがコンフリクトする可能性を減らします。

  8. Remove the "/etc/apt/preferences" file (disable apt-pinning).

  9. 段階的にアップグレードしましょう: 旧安定版 oldstable → 安定版 stable → テスト版 testing → 不安定版 unstable

  10. Update the source list to point to new archive only and run "aptitude update".

  11. "aptitude install perl" 等として、先に新規の中核的パッケージを必要に応じてインストールします。

  12. "apt-get -s dist-upgrade" コマンドを実行して影響を確認します。

  13. 最後に "apt-get dist-upgrade" コマンドを実行します。

[注意] 注意

stable リリース間でアップグレードする際に Debian のメジャーリリースを飛ばすのは賢明ではありません。

[注意] 注意

過去の "リリースノート" ではシステム全体のアップグレードをするのに GCC や Linux カーネルや initrd-tools や Glibc や Perl や APT tool chain 等には特別な配慮が必要でした。

unstable での毎日のアップグレードは「パッケージ問題からの防御」を参照下さい。

aptitude ではハイレベル過ぎるとか必要な機能を欠くという他のパッケージ管理操作のリストです。

表2.13 高度なパッケージ管理操作

コマンド アクション
COLUMNS=120 dpkg -l パッケージ名パターン バグレポートのためにインストールされたパッケージの状態をリスト
dpkg -L パッケージ名 インストールされたパッケージの内容をリスト
dpkg -L パッケージ名 | egrep '/usr/share/man/man.*/.+' インストールされたパッケージのマンページをリスト
dpkg -S ファイル名パターン マッチするファイル名があるインストールされたパッケージをリスト
apt-file search ファイル名パターン マッチするファイル名があるアーカイブ中のパッケージをリスト
apt-file list パッケージ名パターン アーカイブ中のマッチするパッケージをリスト
dpkg-reconfigure パッケージ名 特定パッケージを再設定
dpkg-reconfigure -plow パッケージ名 もっとも詳細な質問で特定パッケージを再設定
configure-debian フルスクリーンメニューからパッケージを再設定
dpkg --audit 部分的にインストールされたパッケージに関してシステムを監査
dpkg --configure -a 全ての部分的にインストールされたパッケージを設定
apt-cache policy バイナリーパッケージ名 バイナリーパッケージに関して利用可能なバージョンやプライオリティーやアーカイブ情報を表示
apt-cache madison パッケージ名 パッケージに関して利用可能なバージョンやアーカイブ情報を表示
apt-cache showsrc バイナリーパッケージ名 バイナリーパッケージに関してソースパッケージの情報を表示
apt-get build-dep パッケージ名 パッケージをビルドするのに必要なパッケージをインストール
aptitude build-dep package_name パッケージをビルドするのに必要なパッケージをインストール
apt-get source パッケージ名 (標準アーカイブから) ソースをダウンロード
dget URL for dsc file (他のアーカイブから) ソースをダウンロード
dpkg-source -x パッケージ名_バージョン-debianのレビジョン.dsc ソースパッケージの組 ("*.tar.gz" と "*.debian.tar.gz" / "*.diff.gz") からソースツリーをビルド
debuild binary ローカルのソースツリーからパッケージをビルド
make-kpkg kernel_image カーネルソースツリーからカーネルパッケージをビルド
make-kpkg --initrd kernel_image カーネルソースツリーから initramfs を有効にしてカーネルパッケージをビルド
dpkg -i パッケージ名_バージョン-debianのレビジョン_アーキテクチャー名.deb ローカルパッケージをシステムにインストール
apt install /path/to/package_filename.deb 自動的に依存関係を解決しながらローカルパッケージをシステムにインストールする
debi パッケージ名_バージョン-debianのレビジョン_アーキテクチャー名.dsc ローカルパッケージ (複数) をシステムにインストール
dpkg --get-selections '*' >selection.txt dpkg レベルのパッケージ選択状態情報を保存
dpkg --set-selections <selection.txt dpkg レベルのパッケージ選択状態情報を設定
echo package_name hold | dpkg --set-selections 特定パッケージの dpkg レベルのパッケージ選択状態を hold にする ("aptitude hold package_name" と等価)

[注記] 注記

multi-arch 機能のあるパッケージに関して、一部のコマンドはアーキテクチャー名を必要があるかもしれません。例えば、amd64 アーキテクチャーの libglib2.0-0 パッケージの内容をリストするには "dpkg -L libglib2.0-0:amd64" を使います。

[注意] 注意

"dpkg -i …" や "debi …" といった低いレベルのパッケージツールはシステム管理者によって注意深く使われなければいけません。必要なパッケージ依存関係を自動的に面倒見てくれません。Dpkg の "--force-all" や類似のコマンドラインオプション (dpkg(1) 参照下さい) はエキスパートだけが使うようにできています。十分にその影響を理解せずに使うとシステム全体を壊してしまうかもしれません。

以下に注意下さい。

debsums をインストールすると debsums(1) を使って "/var/lib/dpkg/info/*.md5sums" ファイル中の MD5sum 値との比較でインストールされたパッケージファイルを検証できます。MD5sum がどのような仕組かは「MD5 和」参照下さい。

[注記] 注記

侵入者によって MD5sum のデーターベースが改竄されているかもしれないので debsums(1) はセキュリティーツールとしては限定的有用性しかありません。管理者によるローカルの変更や記憶メディアのエラーによる損傷を点検するぐらいには有用です。

最近は Debian サイトの https://packages.debian.org/ を訪問するとパッケージメタデーターの検索を簡単に出きるようになっていますが、より伝統的な方法を見てみます。

grep-dctrl(1) や grep-status(1) や grep-available(1) コマンドは Debian のパッケージコントロールファイルの一般的フォーマットに従ういかなるファイルを検索するのにも使えます。

The "dpkg -S file_name_pattern" can be used to search package names which contain files with the matching name installed by dpkg. But this overlooks files created by the maintainer scripts.

dpkg のメタデーターに関してより詳細な検索をする必要がある場合、"/var/lib/dpkg/info/" ディレクトリーで "grep -e regexパターン *" コマンドを実行しないといけません。こうすることでパッケージスクリプトやインストール時の質問テキスト中の言葉まで検索できます。

パッケージ依存関係を再帰的に検索したい際には、apt-rdepends(8) を使います。

Debian のパッケージ管理システムが内部的のどのように機能するのかを学びます。何らかのパッケージ問題が発生した際にあなた自身の解決を見出すのに役立つでしょう。

各ディストリビューションのメタデーターのファイルは例えば "http://deb.debian.org/debian/" のような各 Debian ミラーサイトの "dist/コード名" の下に保存されています。そのアーカイブ構造はウェッブブラウザーで閲覧できます。6つのタイプの重要メタデーターがあります。


最近のアーカイブではネットワークトラフィックを減らすべく圧縮された差分ファイルとしてこれらのメタデーターは保存されています。

[ヒント] ヒント

セキュアー APT システムではトップレベルの "Release" ファイルがアーカイブを署名するのに使われています。

Debian アーカイブの各スイーツには例えば次に示すような "http://deb.debian.org/debian/dists/unstable/Release" のようなトップレベルの "Release" ファイルがあります。

Origin: Debian
Label: Debian
Suite: unstable
Codename: sid
Date: Sat, 14 May 2011 08:20:50 UTC
Valid-Until: Sat, 21 May 2011 08:20:50 UTC
Architectures: alpha amd64 armel hppa hurd-i386 i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390 sparc
Components: main contrib non-free
Description: Debian x.y Unstable - Not Released
MD5Sum:
 bdc8fa4b3f5e4a715dd0d56d176fc789 18876880 Contents-alpha.gz
 9469a03c94b85e010d116aeeab9614c0 19441880 Contents-amd64.gz
 3d68e206d7faa3aded660dc0996054fe 19203165 Contents-armel.gz
...
[注記] 注記

「Debian アーカイブの基本」の中で "スイーツ (suite)" や "コード名 (codename)" を使う理由はこれを見れば分かるでしょう。"ディストリビューション" は "スイーツ" と "コード名" との両方を指したい際に用いられます。アーカイブが提供する全アーカイブ "エリア (area)" 名が "Components" の下にリストされます。

The integrity of the top level "Release" file is verified by cryptographic infrastructure called the secure apt as described in apt-secure(8).

  • 暗号手法による署名ファイル "Release.gpg" は真正のトップレベルの "Release" ファイルと秘密の Debian アーカイブキーから作成されます。

  • The public Debian archive keys are locally installed by the latest debian-archive-keyring package.

  • The secure APT system automatically verifies the integrity of the downloaded top level "Release" file cryptographically by this "Release.gpg" file and the locally installed public Debian archive keys.

  • "全ての Packages" と "Sources ファイルの整合性はそのトップレベルの "Release" ファイル中の MD5sum 値を用いて検証します。"パッケージファイルの整合性は "Packages" や "Sources" ファイル中の MD5sum 値を用いて検証します。debsums(1) と「インストールされたパッケージファイルの検証」を参照下さい。

  • 暗号学手法を用いた署名の検証は MD5sum 値の計算よりも非常に CPU を使うプロセスなので、トップレベルの "Release" ファイルには暗号学手法を用いた署名を使いつつ各パッケージには MD5sum 値を用いることでパーフォーマンスを保ったまま良好なセキュリティーが確保できます (「データーセキュリティーのインフラ」参照下さい)。

If the source list entry specifies the "signed-by" option, the integrity of its downloaded top level "Release" file is verified using specified public key. This is useful when the source list contains non-Debian archives.

[ヒント] ヒント

The use of apt-key(8) command for APT key management is deprecated.

Also, you can manually verify the integrity of the "Release" file with the "Release.gpg" file and the public Debian archive key posted on ftp-master.debian.org using gpg.

[ヒント] ヒント

アーカイブレベルの "Release" ファイルが apt_preferences(5) のルールに使われます。

There are archive level "Release" files for all archive locations specified by the source list, such as "http://deb.debian.org/debian/dists/unstable/main/binary-amd64/Release" or "http://deb.debian.org/debian/dists/sid/main/binary-amd64/Release" as follows.

Archive: unstable
Origin: Debian
Label: Debian
Component: main
Architecture: amd64
[注意] 注意

"Archive:" スタンザには、Debian アーカイブではスイート名 ("stable" や "testing" や "unstable" 等) が使われますが、Ubuntu アーカイブではコード名 ("trusty" や "xenial" や "artful" 等) が使われます。

experimentalbookworm-backports のような自動的にインストールされるべきでないパッケージを含むような一部アーカイブでは次に示す "http://deb.debian.org/debian/dists/experimental/main/binary-amd64/Release" のような追加の行があります。

Archive: experimental
Origin: Debian
Label: Debian
NotAutomatic: yes
Component: main
Architecture: amd64

"NotAutomatic: yes" となっていない通常のアーカイブではデフォールトの Pin-Priority 値は 500 ですが、"NotAutomatic: yes" となっている特別なアーカイブではデフォールトの Pin-Priority 値は 1 です (apt_preferences(5) と「Tweaking candidate version with apt-pinning参照下さい)。

When APT tools, such as aptitude, apt-get, synaptic, apt-file, auto-apt, … are used, we need to update the local copies of the meta data containing the Debian archive information. These local copies have following file names corresponding to the specified distribution, area, and architecture names in the source list (see 「Debian アーカイブの基本」).

  • "/var/lib/apt/lists/deb.debian.org_debian_dists_ディストリビューション_Release"

  • "/var/lib/apt/lists/deb.debian.org_debian_dists_ディストリビューション_Release.gpg"

  • "/var/lib/apt/lists/deb.debian.org_debian_dists_ディストリビューション_エリア_source_Sources"

  • "/var/lib/apt/lists/deb.debian.org_debian_dists_ディストリビューション_エリア_source_Sources"

  • "/var/cache/apt/apt-file/deb.debian.org_debian_dists_ディストリビューション_Contents-アーキテクチャー.gz" (apt-file 用)

First 4 types of files are shared by all the pertinent APT commands and updated from command line by "apt-get update" or "aptitude update". The "Packages" meta data are updated if the "deb" is specified in the source list. The "Sources" meta data are updated if the "deb-src" is specified in the source list.

"Packages" や "Sources" メタデーターはバイナリーやソースパッケージのファイルの場所を指している "Filename:" スタンザを含んでいます。現在、それらのパッケージはリリース間の移行を滞り無くするために "pool/" ディレクトリーツリーの下に置かれています。

"Packages" メタデーターのローカルコピーは aptitude を使ってインタラクティブに検索できます。grep-dctrl(1) という専用の検索コマンドを使うと "Packages" と "Sources" メタデーターのローカルコピーを検索できます。

"Contents-アーキテクチャー" メタデーターのローカルコピーは "apt-file update" で更新でき、他の4つと異なるところにあります。apt-file(1) を参照下さい。(auto-apt では "Contents-アーキテクチャー.gz" のローカルコピーがデフォールトでは異なるところにあります。)

Debian のパッケージファイルには特定の名前の構造があります。


[ヒント] ヒント

ここでは基本的なパッケージフォーマットのみが記述されています。詳細は dpkg-source(1) を参照下さい。


[注記] 注記

パッケージバージョンの順位は dpkg(1) を使って、例えば "dpkg --compare-versions 7.0 gt 7.~pre1 ; echo $?" とすると確認できます。

[注記] 注記

Debian インストーラー (d-i) のバイナリーパッケージには、通常の deb ではなく udeb をファイル拡張子として使われます。udeb パッケージはポリシー条件を緩和しドキュメントのように必須でない内容を削除した減量 deb パッケージです。debudeb パッケージは同一のパッケージ構造を共有しています。"u" はマイクロと言う意味で使っています。

dpkg(1) は Debian パッケージ管理の最も低レベルのツールです。非常に強力ですから気をつけて使う必要があります。

"パッケージ名"というパッケージをインストールする際に、dpkg は次に記す順番でパッケージを処理します。

  1. deb ファイルを解凍 ("ar -x" と等価)

  2. debconf(1) を使い "package_name.preinst" を実行

  3. システムにパッケージ内容をインストール ("tar -x" と等価)

  4. debconf(1) を使い "package_name.postinst" を実行

debconf システムによって I18N と L10N (8章I18N と L10N) のサポートのある標準化されたユーザーとの対話が実現できます。

表2.17 dpkg が作成する特記すべきファイル

ファイル 内容の説明
/var/lib/dpkg/info/パッケージ名.conffiles 設定ファイルのリスト。(ユーザー変更可能)
/var/lib/dpkg/info/パッケージ名.list パッケージによりインストールされるファイルやディレクトリーのリスト
/var/lib/dpkg/info/パッケージ名.md5sums パッケージによりインストールされるファイルの MD5 ハッシュ値のリスト
/var/lib/dpkg/info/パッケージ名.preinst パッケージインストールの前に実行するパッケージスクリプト
/var/lib/dpkg/info/パッケージ名.postinst パッケージインストールの後に実行するパッケージスクリプト
/var/lib/dpkg/info/パッケージ名.prerm パッケージ削除の前に実行するパッケージスクリプト
/var/lib/dpkg/info/パッケージ名.prerm パッケージ削除の前に実行するパッケージスクリプト
/var/lib/dpkg/info/パッケージ名.conffiles debconf システムのためのパッケージスクリプト
/var/lib/dpkg/alternatives/パッケージ名 update-alternatives コマンドが用いる代替情報
/var/lib/dpkg/available すべてのパッケージの入手可能性情報
/var/lib/dpkg/diversions dpkg(1) が利用し、dpkg-divert(8) が設定するする迂回情報
/var/lib/dpkg/statoverride dpkg(1) が利用し、dpkg-statoverride(8) が設定する状態オーバーライド情報
/var/lib/dpkg/status 全パッケージに関する状態情報
/var/lib/dpkg/status-old "var/lib/dpkg/status" ファイルの第一世代のバックアップ
/var/backups/dpkg.status* "var/lib/dpkg/status" ファイルの第二世代以前のバックアップ

"status" ファイルは dpkg(1) や "dselect update" や "apt-get -u dselect-upgrade" のようなツールによって使われます。

grep-dctrl(1) という専用の検索コマンドを使うと "status" と "available" メタデーターのローカルコピーを検索できます。

[ヒント] ヒント

デビアンインストーラー 環境下では、udpkg コマンドが udeb パッケージを開けるのに用いられます。udpkg コマンドはストリップダウンされたバージョンの dpkg コマンドです。

When running testing or unstable system, the administrator is expected to recover from broken package management situation.

[注意] 注意

ここで説明するいくつかの方法は非常にリスクが高いアクションです。警告しましたよ!

Caching errors of the package data cause intriguing errors, such as "GPG error: ... invalid: BADSIG ..." with APT.

You should remove all cached data by "sudo rm -rf /var/lib/apt/* " and try again. (If apt-cacher-ng is used, you should also run "sudo rm -rf /var/cache/apt-cacher-ng/* ".)

aptitude(8) や apt-get(1) 等の、アーカイブレベルのパッケージ管理システムはパッケージの依存関係を使って重複するファイルを持つファイルのインストールしようとさえしません (「パッケージ依存関係」参照下さい)。

パッケージメインテナによるエラーや、システム管理者による不整合な混合ソースのアーカイブの採用 (「Packages from mixed source of archives without apt-pinning参照下さい) があった場合には、パッケージ依存関係が誤って定義される事態が発生するかもしれません。そういう状況下で重複するファイルを持つパッケージを aptitude(8) や apt-get(1) を使ってインストールしようとすると、パッケージを展開する dpkg(1) は既存ファイルを上書きすることなく呼ばれたプログラムにエラーを確実に返します。

[注意] 注意

第三者が作成したパッケージを使うと、root 権限で実行されるシステムに関して何でもできるメンテナスクリプトが実行されるので、システムが重大なリスクにさらされます。dpkg(1) はパッケージを展開するするさいに上書きする事を防止するだけです。

そのような壊れたインストール状況は、まず古い問題原因となっているパッケージ old-package を削除すれば回避できます。

$ sudo dpkg -P old-package

dpkg は非常に低レベルのパッケージツールなのでネットワーク接続もないブート不能な非常に劣悪な状況下でも機能します。foo パッケージが壊れていて置き換える必要があると仮定します。

バグの無い古いバージョンの foo パッケージが "/var/cache/apt/archives/" にあるパッケージキャッシュの中に見つかるかもしれません。(ここにみつからなければ、https://snapshot.debian.org/ アーカイブからダウンロードしたり、機能している機器のパッケージキャッシュからコピーできます。)

もしブート不可能な場合には、次のコマンドを使ってインストールすることもできます。

# dpkg -i /path/to/foo_old_version_arch.deb
[ヒント] ヒント

システムがそれほど壊れていないなら、「緊急ダウングレード」に書かれているようにして、より高レベルの APT システムを通じてシステム全体をダウングレードする手もあります。

ハードディスクからブートできない場合は、他の方法でのブート方法を考えるべきです。

  1. Debian インストーラー (debian-installer) の CD を使ってレスキューモードでブートします。

  2. ブートできないハードディスク上のシステムを "/target" にマウントします。

  3. 古いバージョンの foo パッケージを次のようにしてインストールします。

# dpkg --root /target -i /path/to/foo_old_version_arch.deb

この例は、たとえハードディスク上の dpkg コマンドが壊れていても機能します。

[ヒント] ヒント

ハードディスク上の別のシステムであれ、GNU/Linux のライブ CD であれ、ブート可能な USB キードライブであれ、ネットブートであれ、どのように起動された GNU/Linux システムでも同様にして壊れたシステムを救済するのに使えます。

もしこの方法でパッケージをインストールしようとして何らかの依存関係違反のためにうまくいかなくてどうしようもなくなった場合には、dpkg の "--ignore-depends" や "--force-depends" や他のオプションを使って依存関係をオーバーライドすることができます。こうした場合には、後で適正な依存関係を修復するように真剣に取り組む必要があります。詳細は dpkg(8) を参照下さい。

[注記] 注記

システムがひどく壊れた場合には、システムを安全な場所に完全バックアップし (「バックアップと復元」参照下さい)、クリーンインストールを実行するべきです。こうすることは時間の節約でもあり最終的に良い結果に結びつきます。

For simplicity, the source list examples in this section are presented as "/etc/apt/sources.list" in one-line-style after the bookworm release.

apt パッケージには、パッケージの自動ダウンロードのサポートする専用の cron スクリプト "/etc/cron.daily/apt" が同梱されています。このスクリプトは unattended-upgrades パッケージをインストールすることで自動アップグレード実行の機能拡張をします。これらは、"/usr/share/doc/unattended-upgrades/README" に記述されているように、"/etc/apt/apt.conf.d/02backup" と "/etc/apt/apt.conf.d/50unattended-upgrades" の中のパラメーターでカスタム化できます。

unattended-upgrades パッケージは基本的に stable システムのセキュリティーアップグレードのためです。既存の stable システムが、自動アップグレードで壊される危険性が、セキュリティーアップグレードがすでに閉じたセキュリティーホールからの侵入者によりシステムが壊わされる危険性より小さいなら、パラメーターを次のように設定して自動アップグレードをするのも一計です。

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::Unattended-Upgrade "1";

If you are running an testing or unstable system, you do not want to use the automatic upgrade since it certainly breaks system some day. Even for such testing or unstable case, you may still want to download packages in advance to save time for the interactive upgrade with configuration parameters as the following.

APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::Unattended-Upgrade "0";

There are stable-updates ("bookworm-updates" during the bookworm-as-stable release cycle) and backports.debian.org archives which provide upgrade packages for stable.

これらのアーカイブを使うには、以下に示すように "/etc/apt/preferences" ファイル中に全ての必要なアーカイブをリストします。

deb http://deb.debian.org/debian/ bookworm main non-free-firmware contrib non-free
deb http://security.debian.org/debian-security bookworm-security main non-free-firmware contrib non-free
deb http://deb.debian.org/debian/ bookworm-updates main non-free-firmware contrib non-free
deb http://deb.debian.org/debian/ bookworm-backports main non-free-firmware contrib non-free

"/etc/apt/preferences" ファイル中に Pin-Priority 値を明示的に設定する必要はありません。より新しいパッケージが利用可能となった場合はいつも、デフォルトの設定によりもっとも合理的なアップグレードがなされます (「アーカイブレベルの "Release" ファイル」 参照下さい)。

  • 全てのインストールされている古いパッケージが bookworm-updates からのより新しいパッケージにアップグレードされます。

  • bookworm-backports からインストールしされた古いパッケージのみが bookworm-backports からのより新しいパッケージにアップグレードされます。

"package-name" という名前のパッケージをその依存関係ともども bookworm-backports アーカイブからインストールしたい時には、"-t" オプションでターゲットリリースを切り替えながら次のコマンドを使います。

$ sudo apt-get install -t bookworm-backports package-name
[警告] 警告

Do not install too many packages from backports.debian.org archives. It may cause package dependency complications. See 「How to cope with conflictig requirements」 for alternative solutions.

[注意] 注意

Installing packages from mixed source of archives is not supported by the official Debian distribution except for officially supported particular combinations of archives such as stable with security updates and stable-updates.

testing を追跡しながら、unstable にある特定の新規アップストリームバージョンのパッケージを1回だけ取り入れる操作例を次に示します。

  1. "/etc/apt/sources.list" ファイルを変更し、単一の "unstable" エントリーのみにします。

  2. "aptitude update" を実行します。

  3. "aptitude install パッケージ名"の実行します。

  4. testing のためのオリジナルの "/etc/apt/sources.list" ファイルを復元します。

  5. "aptitude update" を実行します。

You do not create the "/etc/apt/preferences" file nor need to worry about apt-pinning with this manual approach. But this is very cumbersome.

[注意] 注意

混合したアーカイブソースを使うことを Debian が保証していないので、その場合にはパッケージ間の互換性は自分自身で確保しなければいけません。もしパッケージに互換性がないと、システムを壊すことになるかもしれません。この様な技術的要件を判断できる必要があります。ランダムな混合したアーカイブソースを使うことは全く任意の操作ですが、私としてはこの操作はお薦めできません。

異なるアーカイブからパッケージをインストールするための一般ルールは以下です。

[注記] 注記

パッケージを比較的安全にインストールできるようにするために、一部の商用 non-free バイナリープログラムパッケージは完全に静的にリンクされたライブラリーとともに提供される事があります。そんなパッケージに関しても ABI 互換性等の問題は確認するべきです。

[注記] 注記

Except to avoid broken package for a short term, installing binary packages from non-Debian archives is generally bad idea. You should seek all available alternative safer technical solutions which are compatible with your current Debian syetem (see 「How to cope with conflictig requirements」).

[警告] 警告

Use of apt-pinning by a novice user is sure call for major troubles. You must avoid using apt-pinning except when you absolutely need it.

"/etc/apt/preferences" ファイル無しだと、APT システムはバージョン文字列を用いて、最新利用可能バージョンを候補バージョンとします。これが通常状態で APT システムの最も推薦される使い方です。全ての公式にサポートされたアーカイブの組み合わせは、自動的にアップグレードするソースとすべきでないアーカイブは NotAutomatic とマークされ適正な扱いを受けるので、"/etc/apt/preferences" ファイルを必要としません。

[ヒント] ヒント

バージョン文字列比較ルールは、例えば "dpkg --compare-versions ver1.1 gt ver1.1~1; echo $?" とすれば確認できます (dpkg(1) 参照下さい)。

パッケージを混合したアーカイブからのソース (「Packages from mixed source of archives without apt-pinning参照下さい) から定常的にインストールする場合には、apt_preferences(5) に書かれたように適正な項目のある "/etc/apt/preferences" ファイルを作り候補バージョンに関するパッケージ選択ルールを操作することによってこういった複雑な操作を自動化できます。これを apt-pinning と呼びます。

When using apt-pinning, you must ensure compatibility of packages by yourself since the Debian does not guarantee it. The apt-pinning is completely optional operation and its use is not something I encourage you to use.

Archive level Release files (see 「アーカイブレベルの "Release" ファイル」) are used for the rule of apt_preferences(5). Thus apt-pinning works only with "suite" name for normal Debian archives and security Debian archives. (This is different from Ubuntu archives.) For example, you can do "Pin: release a=unstable" but can not do "Pin: release a=sid" in the "/etc/apt/preferences" file.

When you use non-Debian archive as a part of apt-pinning, you should check what they are intended for and also check their credibility. For example, Ubuntu and Debian are not meant to be mixed.

[注記] 注記

Even if you do not create the "/etc/apt/preferences" file, you can do fairly complex system operations (see 「dpkg コマンドを使っての救済」 and 「Packages from mixed source of archives without apt-pinning) without apt-pinning.

単純化した apt-pinning テクニックの説明を次にします。

APT システムは "/etc/apt/sources.list" ファイル中に規定された利用可能なパッケージソースから最高の Pin-Priority でアップグレードするパッケージを候補バージョンパッケージとして選択します。パッケージの Pin-Priority が1000 より大きい場合には、このアップグレードするというバージョン制約が外れるのでダウングレードできるようになります (「緊急ダウングレード」参照下さい)。

各パッケージの Pin-Priority 値は "/etc/apt/preferences" ファイル中の "Pin-Priority" 項目にて規定されるか、そのデフォールト値が使われます。


ターゲットのリリースアーカイブは次のようにして設定できます。

  • "APT::Default-Release "stable";" 行を使う "/etc/apt/apt.conf" ファイル

  • "apt-get install -t testing some-package" 等の "-t" オプションの引数

アーカイブ中のアーカイブレベルの Release ファイル (「アーカイブレベルの "Release" ファイル」参照下さい) に "NotAutomatic: yes" や "ButAutomaticUpgrades: yes" が含まれると NotAutomatic かつ ButAutomaticUpgrades アーカイブと設定されます。

複数アーカイブソースの package に関する Pin-Priority 値は "apt-cache policy package" の出力で表示されます。

  • "Package pin:" で始まる行は、package のみとの関連付けが "Package pin: 0.190" 等と定義されている場合に、pin のパッケージバージョンを示します。

  • package とのみの関連付けが定義されていない場合には、"Package pin:" という行はありません。

  • package とのみの関連付けが定義されている場合の Pin-Priority 値は、全バージョン文字列の右側に "0.181 700" 等としてリストされます。

  • package とのみの関連付けが定義されていない場合には、全バージョン文字列の右側に "0" が"0.181 0" 等としてリストされます。

  • アーカイブの Pin-Priority 値 ("/etc/apt/preferences" ファイル中に "Package: *" として定義) はアーカイブへのパスの左側に、"100 http://deb.debian.org/debian/ bookworm-backports/main Packages" 等としてリストされます。

[警告] 警告

Use of apt-pinning by a novice user is sure call for major troubles. You must avoid using apt-pinning except when you absolutely need it.

testing を追跡しながら、unstable にある特定の新規アップストリームバージョンのパッケージが定常的にアップグレードされる、apt-pinning テクニックの例を次に示します。全ての必要なアーカイブを "/etc/apt/sources.list" ファイル中に次のようにリストします。

deb http://deb.debian.org/debian/ testing main contrib non-free
deb http://deb.debian.org/debian/ unstable main contrib non-free
deb http://security.debian.org/debian-security testing-security main contrib

"/etc/apt/preferences" を次のように設定します。

Package: *
Pin: release a=unstable
Pin-Priority: 100

"package-name" という名前のパッケージとその依存ファイルを unstable アーカイブからこの設定の下でインストールしたい場合、"-t" オプションを使ってターゲットのリリースを切り替える (unstable の Pin-Priority が990 になる) 次のコマンドを実行します。

$ sudo apt-get install -t unstable package-name

この設定では、通常の "apt-get upgrade" や "apt-get dist-upgrade" ("aptitude safe-upgrade" や "aptitude full-upgrade") の実行は、testing アーカイブからインストールされたパッケージは最新の testing アーカイブを使ってアップグレードし、unstable アーカイブからインストールされたパッケージは最新の unstable アーカイブを使ってアップグレードします。

[注意] 注意

"/etc/apt/sources.list" ファイルから "testing" の項目を削除しないように注意します。"testing" 項目がその中にないと、APT システムは最新の unstable アーカイブを使ってアップグレードします。

[ヒント] ヒント

著者は上記操作のすぐ後に "/etc/apt/sources.list" ファイルを編集して "unstable" アーカイブ項目をコメントアウトします。こうすることで、最新の unstable アーカイブによって unstable からインストールされたパッケージをアップグレードしなくなりますが、"/etc/apt/sources.list" ファイル中に項目が多すぎてアップデートのプロセスが遅くなることをさけられます。

[ヒント] ヒント

もし "/etc/apt/preferences" ファイル中で "Pin-Priority: 100" の代わりに "Pin-Priority: 1" が用いられた場合は、"/etc/apt/sources.list" ファイルの中の "testing" 項目が削除されようと、Pin-Priority 値は100 のインストール済みパッケージは unstable アーカイブによってアップグレードされる事はありません。

最初の "-t unstable" によるインストール無しに、unstable の特定パッケージを自動的に追跡したい場合、"/etc/apt/preferences" ファイルを作りそのトップにこれらパッケージを明示的に次のようにリストします。

Package: package-1
Pin: release a=unstable
Pin-Priority: 700

Package: package-2
Pin: release a=unstable
Pin-Priority: 700

以上で、各特定パッケージに関して Pin-Priority 値が設定されます。例えば最新の unstable バージョンのこの "Debian リファレンス" を英語版で追跡するためには、"/etc/apt/preferences" ファイルに次の項目を設定します。

Package: debian-reference-en
Pin: release a=unstable
Pin-Priority: 700

Package: debian-reference-common
Pin: release a=unstable
Pin-Priority: 700
[ヒント] ヒント

This apt-pinning technique is valid even when you are tracking stable archive. Documentation packages have been always safe to install from unstable archive in my experience, so far.

[警告] 警告

Use of apt-pinning by a novice user is sure call for major troubles. You must avoid using apt-pinning except when you absolutely need it.

[注意] 注意

Debian では設計としてはダウングレードを正式にサポートしません。緊急の復元処置の一部としてのみ実行されるべきです。こういう状況であるにもかかわらず、多くの場合にうまく機能することが知られています。重要なシステムでは回復処置の後に全ての重要データーをバックアップし、最初から新規システムを再インストールします。

壊れたシステムアップグレードからの復元するために、候補バージョンを操作して新しいアーカイブから古いアーカイブにダウングレードすることがうまくいくかもしれません (「Tweaking candidate version with apt-pinning参照下さい)。これは、何度も "dpkg -i broken-package_old-version.deb" コマンドを実行する退屈な作業をしないでよくする方法です (「dpkg コマンドを使っての救済」参照下さい)。

次に記すような "unstable" を追跡する "/etc/apt/sources.list" ファイル中の行を探します。

deb http://deb.debian.org/debian/ sid main contrib non-free

それを testing を追いかけるように次と交換します。

deb http://deb.debian.org/debian/ trixie main contrib non-free

"/etc/apt/preferences" を次のように設定します。

Package: *
Pin: release a=testing
Pin-Priority: 1010

"apt-get dist-upgrade" を実行して、システム全体にわたってパッケージのダウングレードを強制します。

この緊急ダウングレードの後でこの特別の "/etc/apt/preferences" ファイルを削除します。

[ヒント] ヒント

依存関係の問題を最小限とすべく、できるだけ多くのパッケージを削除 (remove で、完全削除 purge ではありません!) します。システムのダウングレードのためには手動でいくつかのパッケージを削除とインストールしなければいけないかも知れません。Linux カーネルやブートローダーや udev や PAM や APT やネットワーク関係のパッケージやそれらの設定ファイルには特に注意が必要です。

Debian アーカイブの特定サブセクション全てをミラーするとディスク空間とネットワークのバンド幅の大いなる無駄遣いですので、LAN 上に多くのシステムを管理している際には APT のためのローカルのプロキシサーバーを設置することを考えるのは良いことです。APT は、apt.conf(5) とか "/usr/share/doc/apt/examples/configure-index.gz" に説明されたようにして、汎用の squid のような ウェッブ (http) プロキシサーバー (「他のネットワークアプリケーションサーバー」参照下さい) を使うように設定できます。"$http_proxy" 環境変数による設定は、"/etc/apt/apt.conf" ファイル中の設定より優先します。

Debian アーカイブ専用のプロキシツールがあります。実際に使う前に BTS をチェック下さい。


[注意] 注意

Debian がそのアーカイブ構造を再編した際に、このような専用のプロキシツールはパッケージメンテナによるコードの修正が必要で、一定期間使えなくなることがあります。一方、汎用のウェッブ (http) プロキシは比較的堅牢ですしそのような変化に合わすのも簡単です。