0

Imagine a package foo that has a recommended dependency bar and a suggested dependency baz. How do I configure APT for the following behavior?

  1. apt install foo: installs foo and bar; does not install baz
  2. apt autoremove: no changes
  3. apt remove foo: uninstalls foo
  4. apt autoremove: uninstalls bar

I have tried setting these options in /etc/apt/apt.conf.d/99-norecommends:

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

But, in the scenario above, this results in bar being uninstalled in step 2.

What is the right combination of APT configuration options to meet my goal?

Update: I've installed a fresh instance of Debian in a VM, made no config changes, and ran the following commands:

  1. apt update; apt upgrade: nothing was out-of-date
  2. apt install exim4: lots of stuff was installed (apologies for any typos, I transcribed these manually out of the VM)
    • exim4-base
    • mariadb-common
    • libwrap0
    • libython2.7
    • exim4-daemon-light
    • libltd17
    • libunbound8
    • mailutils-common
    • libgsas17
    • psmisc
    • exim4-config
    • libntlm0
    • guile-2.2-libs
    • mailutils
    • mysql-common
    • libmailutils5
    • exim4
    • libevent-2.1-6
    • libmariadb3
    • libgc1c2
    • libgnutls-dane0
    • libkyotocabinet16v5
    • libfribidi0
    • liblz02-2
  3. apt purge exim4: exim4 was uninstalled
  4. apt autoremove: nothing was uninstalled

How do I get the other 23 packages to be removed automatically? I don't want to be looking back in my apt logs to try to reconstruct what needs to be done to fully reverse an apt install {...} command, especially if there were intervening installations that could require some of the automatically-installed packages.

By the way, this clearly conflicts with the man page for apt-get:

remove

remove is identical to install except that packages are removed instead of installed.

purge

purge is identical to remove except that packages are removed and purged

My testing above shows that install and remove/purge are not symmetric as stated there.

5
  • What you ask for - except not to install recommendations - is standard apt. I'm afraid your changes did more harm then good. Commented Dec 21, 2020 at 6:08
  • @GerardH.Pille I've updated my question with a concrete example demonstrating the behavior I would like to obtain Commented Jan 27, 2021 at 7:15
  • Again: you wish for standard behaviour. Check your config for changes. Commented Jan 27, 2021 at 7:27
  • This is happening in a completely fresh virtual machine installed from the official Debian ISO that I downloaded this evening. I've made no config changes. I agree with you that the behavior I want seems expected, but it's not working that way for me. Commented Jan 27, 2021 at 7:37
  • 1
    I wondered why this has never bothered me. I just realized that since my first day on Linux ('98 I think), I had Install-Recoommends and -Suggest on false. You are correct: auto-remove and -clean only act on depending packages. I suggest you run a cleanup yourself based on the output of "apt-cache depends exim4", filtering the suggests and recommends. Commented Jan 27, 2021 at 10:29

3 Answers 3

2

Thes are the settings you need:

APT::Get::Install-Recommends "false";
APT::Get::Install-Suggests "false";
3
  • I still want to install the recommend and suggests at installation time, but I would also like them to be uninstalled at removal time. Commented Jan 27, 2021 at 7:15
  • Apt will warn you on next use about such packages, telling you to run "apt autoremove". Commented Jan 27, 2021 at 7:23
  • I ran apt autoremove; nothing was removed. Commented Jan 27, 2021 at 7:34
1
  1. Use apt-mark hold to prevent the desired package from being removed when executing purge or remove.

man apt-mark:

PREVENT CHANGES FOR A PACKAGE

hold
   hold is used to mark a package as held back, which will prevent
the package from being automatically installed, upgraded or removed.

You have already the list of Suggest packages list: package.list

cat package.list |xargs sudo apt-mark hold
  1. Before executing sudo apt autoremove unhold them:

    cat package.list |xargs sudo apt-mark unhold
    
0

Because of my continued confusion on this, I filed a bug with apt https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=981168. Of course, it turns out not to be a bug and to have a reasonable explanation. Quoting from the helpful maintainer Julian Andres Klode (I had given the same example of installing and then uninstalling exim4 as in my question here):

Most likely:

exim4 depends on an exim4-daemon-$something, all of which provide mail-transport-agent. If one installed package depends/recommends/suggests mail-transport-agent, it won't be autoremoved.

This is not a bug, and we might eventually get a cool feature to undo history, but it's not there yet, and I don't want to track it in a bug.

In addition:

As a bonus point; I do have a system cleanup script that removes as many automatically installed packages as possible while keeping all manually insttalled ones:

http://salsa.debian.org/jak/cleanup

Clone that, install clasp, and run ./program_builder.py to have it give you a list of packages that can be removed.

This is very thorough and a lot less safe than apt's autoremove.

I need to work on adding a clasp solving backend to apt, then we can have a thorough autoremove code in apt too (and solve dependencies and order installations as best as possible :D).

Sounds like someday this may get implemented, but until then we might have to look through our APT logs or use the mentioned cleanup script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .