サーバー構築

apt-getによる依存関係の解決方法

apt-getによる依存関係の解決方法

Debianでパッケージ依存関係が発生し、「apt-get -f install」でも、インストールが解決しない場合があります。

2026年11月時点の補足

記事は 2013年の apt-get(Debian 6〜7)での手順です。考え方は今も同じですが、壊れたパッケージを探すコマンドと直すコマンドは、今の apt では次のように書きます。

# dpkg --audit                  ← 設定が終わっていない・壊れたパッケージを一覧表示
# apt --fix-broken install      ← apt-get -f install と同じ
# dpkg --configure -a           ← 途中で止まった設定処理をやり直す
項目この記事(2013年)Debian 13(2026年11月時点)
例に使ったパッケージcacti-spine 0.8.7e-2cacti-spine 1.2.30-1
依存の修復apt-get -f installapt --fix-broken install(apt-get -f install も使える)
状態の確認dpkg -s パッケージ名dpkg --audit で壊れたものをまとめて表示

版は Debian のパッケージ一覧(madison) で 2026年11月5日に確認しました。⚠ 記事の最後の dpkg --force-all -r は依存関係を無視して消すので、ほかのパッケージを道連れに壊すことがあります。使うのは上の 3 つで直らなかったときだけにしてください。

こんなエラーで困った事はありませんか?
E: Sub-process /usr/bin/dpkg returned an error code (1)

今回は、パッケージ「cacti-spine」で試してみます。

// インストール
# apt-get -f install cacti-spine
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  cacti-spine
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/53.9 kB of archives.
After this operation, 180 kB of additional disk space will be used.
Selecting previously deselected package cacti-spine.
(Reading database ... 55470 files and directories currently installed.)
Unpacking cacti-spine (from .../cacti-spine_0.8.7e-2_amd64.deb) ...
Processing triggers for man-db ...
Setting up cacti-spine (0.8.7e-2) ...
Not replacing deleted config file /etc/cacti/spine.conf
chown: cannot access `/etc/cacti/spine.conf': No such file or directory
dpkg: error processing cacti-spine (--configure):
 subprocess installed post-installation script returned error exit status 1
configured to not write apport reports
                                      Errors were encountered while processing:
 cacti-spine
E: Sub-process /usr/bin/dpkg returned an error code (1)

依存関係が発生しインストールする事が出来ませんでした。

そこでインストール出来なかった原因を調べてみます。

// ステータスを調べる
# dpkg -s cacti-spine
Package: cacti-spine
Status: install reinstreq half-installed ← 失敗

// インストールが成功していた場合
Status: install ok installed ← 成功

// 説明
installed(インストールされている)
reinstreq(壊れているので、要再インストール)
half-installed(インストールされているが、何らかの理由で完了していない)

やっぱり失敗していた。そこで下記のコマンド実行。

// 強制的にcacti-spineを削除
# dpkg -P --force-remove-reinstreq cacti-spine
(Reading database ... 55469 files and directories currently installed.)
Removing cacti-spine ...
Purging configuration files for cacti-spine ...

再度チャレンジ

// cacti-spineをインストール
# apt-get -f install cacti-spine
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  cacti-spine
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/53.9 kB of archives.
After this operation, 180 kB of additional disk space will be used.
Selecting previously deselected package cacti-spine.
(Reading database ... 55470 files and directories currently installed.)
Unpacking cacti-spine (from .../cacti-spine_0.8.7e-2_amd64.deb) ...
Processing triggers for man-db ...
Setting up cacti-spine (0.8.7e-2) ...

Creating config file /etc/cacti/spine.conf with new version

無事、「cacti-spine」をインストールすることができました。

これでも依存関係が解決しなかったら、、

dpkg --force-all -rを調べてみると解決する方法が見つかるかもしれません。

パッケージ間の関係に起因するエラーを強制的に無視するものであり、原因を取り除かないままコマンドの実行するようです。あまり推奨される方法ではないようですが参考までに。


// コマンド
# dpkg --force-all -r パッケージ名