4

I have noticed that installing sendmail, then uninstalling it, using apt-get will leave many unwanted files behind.

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

So we installed sendmail - 9 new packages and 5.2MB.
Minutes later, I changed my mind and want to uninstall it. No problem, apt-get got me covered, right? I purge (delete package and package configuration files):

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

Then autoremove (remove automatically installed package dependencies)

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) ...

That's 219 + 550 = 769KB recovered! Did I just loose 4.something MB of space? For what?

Upon looking closely at the output, it appears that apt-get removed only 3 of the package that it previously automatically installed. Package sendmail-base, for example, remains:

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]

So there is some of my wasted space. But why are these automatically installed dependencies still installed?

Rolf
  • 233
  • 2
  • 10

1 Answers1

7

sendmail is a meta package consisting of a set of dependencies. When you install the sendmail metapackage it installs sendmail-bin, amongst other things. This provides a recommended package for cron, for example, but I believe there are also some other packages that recommend packages in the sendmail dependency chain.

Autoremove will not remove auto packages which are recommended by other packages. You can change this behaviour by, for example, adding this apt configuration in /etc/apt/apt.conf.d/99_norec

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

Then run apt-get remove --auto-remove sendmail, and you should see all your sendmail dependant packages being marked for removal, along with some other unrelated things which are now removal candidates due to the overall change in the apt configuration.

Though, I believe this is not recommended (no pun intended). You should deal with these manually if you need to get rid of them.

DJCrashdummy
  • 103
  • 5
Gav
  • 191
  • 3
  • Removing sendmail does not remove sendmail-bin. So sendmail-bin would be a recommended package for another package? I was not aware of the extensive configuration options for apt. Thank you. – Rolf Apr 06 '17 at 00:09
  • 2
    Yeah that's right. Cron is one example. Use aptitude to explore these relationships a bit more visually. – Gav Apr 06 '17 at 00:10
  • I would not want such a behaviour for a few reasons. I am unlikely to be using any automatically installed package directly, so it will just sit there and do nothing. It makes things more complicated. Most users will be under the false impression that the package was uninstalled (whichh would be the intent) when most of it is still there. Finally, I can see this resulting in space usage and bloat over a long period of time which might be difficult to clean up. In my opinion, from an end-user perspective - it is a bad and unelegant design or decision. I wonder why it would be recommended. – Rolf Apr 06 '17 at 00:19
  • 2
    The great thing about it though is you can change it to match your specific needs/scenario. In the majority of cases, the default is better, which is why I imagine the apt team chose that as default! I think there are lots of instances where someone starts using a recommended package that they didn't install directly, then gets confused when it disappears during an autoremove. – Gav Apr 06 '17 at 00:22
  • 1
    I think that the recommended packages remaining on the system would be, in most cases, an unwanted side-effect of installing something. That is why I am not convinced by the default, but anyway, I am happy to see that it is configurable and am thankful for your answer and tips! – Rolf Apr 06 '17 at 00:26
  • btw: at least if you add `APT::AutoRemove::RecommendsImportant "false";` permanently, it won't make much sense without `APT::Install-Recommends "false";` because else you will install all recommended packages and then with the next `autoremove` you uninstall them again. **--** the same is for sure valid for the "Suggests", but these two should be `false` by default. – DJCrashdummy Mar 15 '21 at 16:45
  • e.g. see similar problem but "reverse": https://unix.stackexchange.com/q/478219/ – DJCrashdummy Mar 15 '21 at 16:53