Debian

為什麼“apt-get autoremove sendmail”會留下依賴關係?

  • March 16, 2021

我注意到安裝 sendmail,然後解除安裝它,使用 apt-get 會留下許多不需要的文件。

sudo apt-get install sendmail
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
 liblockfile-bin liblockfile1 make procmail sendmail-base sendmail-bin
 sendmail-cf sensible-mda
Suggested packages:
 make-doc sendmail-doc rmail logcheck resolvconf sasl2-bin
Recommended packages:
 default-mta mail-transport-agent fetchmail
The following NEW packages will be installed:
     liblockfile-bin liblockfile1 make procmail sendmail sendmail-base
     sendmail-bin sendmail-cf sensible-mda
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 2256 kB of archives.
After this operation, 5263 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

所以我們安裝了 sendmail - 9 個新包和 5.2MB。

幾分鐘後,我改變了主意,想解除安裝它。沒問題,apt-get 讓我滿意,對吧?我清除(刪除包和包配置文件):

sudo apt-get purge sendmail
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
 procmail sensible-mda
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
 sendmail*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 219 kB disk space will be freed.
Do you want to continue? [Y/n] y

然後autoremove(刪除自動安裝的包依賴)

sudo apt-get autoremove sendmail
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'sendmail' is not installed, so not removed
The following packages will be REMOVED:
 procmail sensible-mda
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 550 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 24702 files and directories currently installed.)
Removing sensible-mda (8.14.4-8+deb8u1) ...
Removing procmail (3.22-24) ...
Processing triggers for man-db (2.7.0.2-5) ...

即 219 + 550 = 769KB 已恢復!我剛剛釋放了 4.something MB 的空間嗎?為了什麼?

仔細查看輸出後,似乎 apt-get 僅刪除了之前自動安裝的 3 個軟體包。例如,軟體包 sendmail-base 仍然存在:

sudo apt-get remove sendmail-base
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
 sendmail-base sendmail-bin
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 2464 kB disk space will be freed.
Do you want to continue? [Y/n]

所以我浪費了一些空間。但是為什麼還安裝了這些自動安裝的依賴呢?

sendmail 是一個包含一組依賴項的元包。當您安裝 sendmail 元包時,它會安裝 sendmail-bin 等。這為 cron 提供了一個推薦的包,例如,但我相信在 sendmail 依賴鏈中也有一些其他的包推薦包。

Autoremove 不會刪除其他軟體包推薦的自動軟體包。例如,您可以通過添加此 apt 配置來更改此行為/etc/apt/apt.conf.d/99_norec

APT::AutoRemove::RecommendsImportant "false";
APT::AutoRemove::SuggestsImportant "false";

然後執行apt-get remove --auto-remove sendmail,您應該會看到所有與 sendmail 相關的包都被標記為刪除,以及一些其他不相關的東西,由於 apt 配置的整體變化,這些東西現在是刪除的候選對象。

不過,我認為不建議這樣做(沒有雙關語)。如果您需要擺脫它們,您應該手動處理它們。

引用自:https://serverfault.com/questions/842115