Celeb Glow
updates | February 26, 2026

APT: How to install recommended dependencies and not auto-remove them until the installing package is removed

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

3 Answers

Thes are the settings you need:

APT::Get::Install-Recommends "false";
APT::Get::Install-Suggests "false";
3
  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

Because of my continued confusion on this, I filed a bug with apt . 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:

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.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy