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

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

こんなエラーで困った事はありませんか?
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 パッケージ名

読んで頂いて有り難うございます!