![为什么“apt-get autoremove sendmail”会留下依赖关系?](https://linux22.com/image/701834/%E4%B8%BA%E4%BB%80%E4%B9%88%E2%80%9Capt-get%20autoremove%20sendmail%E2%80%9D%E4%BC%9A%E7%95%99%E4%B8%8B%E4%BE%9D%E8%B5%96%E5%85%B3%E7%B3%BB%EF%BC%9F.png)
我注意到,安装 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.几 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]
所以我浪费了一些空间。但是为什么这些自动安装的依赖项仍然安装?
答案1
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 配置的整体变化,一些其他不相关的包现在也成为删除候选。
不过,我认为不建议这么做(没有双关语的意思)。如果你需要摆脱它们,你应该手动处理它们。