apt autoremove does not remove all dependencies even with Apt::AutoRemove::SuggestsImportant "false";

Like mentioned as comment to an answer Debian 9.1: apt-get autoremove will not remove dependencies,
I added the line Apt::AutoRemove::SuggestsImportant "false"; in /etc/apt/apt.conf and then was able to remove g++ that was installed automatically when installing VirtualBox from Debian Fast Track (I am using Debian 12 so I had to replace the codename bullseye with bookworm since the instructions on https://fasttrack.debian.net/ are not updated).

However apt autoremove still does not uninstall other packages installed automatically like libasan8 that are no longer needed. Do you know why and is there a solution to remove them automatically?

Here are all packages installed by executing sudo apt install virtualbox:

build-essential dkms dpkg-dev g++ g++-12 gcc gcc-12 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan8 libc-dev-bin libc-devtools libc6-dev libcc1-0 libcrypt-dev libgcc-12-dev
libgsoap-2.8.124 libitm1 liblsan0 liblzf1 libnsl-dev libstdc++-12-dev libtirpc-dev libtsan2 libubsan1 libvncserver1 linux-compiler-gcc-12-x86 linux-headers-6.1.0-18-amd64 linux-headers-6.1.0-18-common
linux-headers-amd64 linux-kbuild-6.1 linux-libc-dev make manpages-dev patch rpcsvc-proto virtualbox virtualbox-dkms virtualbox-qt

Here are the packages removed by executing sudo apt purge virtualbox:

virtualbox* virtualbox-qt*

These additional packages were removed by executing sudo apt autoremove --purge:

dkms* libgsoap-2.8.124* liblzf1* libvncserver1* linux-headers-amd64* virtualbox-dkms*

By executing the same command after adding Apt::AutoRemove::SuggestsImportant "false"; in /etc/apt/apt.conf, these packages were removed also:

build-essential* dpkg-dev* g++* g++-12* gcc* libalgorithm-diff-perl* libalgorithm-diff-xs-perl* libalgorithm-merge-perl* libstdc++-12-dev* make* patch*

And as requested after my comment, here is the output of aptitude why libasan8:

i   aptitude      Recommends libdpkg-perl               
i A libdpkg-perl  Suggests   gcc | c-compiler           
i A gcc-12        Provides   c-compiler                 
i A gcc-12        Depends    libgcc-12-dev (= 12.2.0-14)
i A libgcc-12-dev Depends    libasan8 (>= 12.2.0-14)
Asked By: baptx

||

The purpose of my answer to Debian 9.1: apt-get autoremove will not remove dependencies was only to make the behaviour of apt install and apt autoremove symmetric — the former ignores “Suggests” dependencies by default, the answer explains how to make the latter ignore them too.

In your case, I don’t think there’s an automated way of removing all the packages pulled in by virtualbox, because one of them is linux-headers-6.1.0-18-amd64, and that is a protected kernel package (see /etc/apt/apt.conf.d/01autoremove on your system). It won’t be a candidate for autoremoval until at least two newer kernels are installed, so you need to remove it manually if you want to get rid of it:

   sudo apt purge linux-headers-6.1.0-18-amd64

There is a corresponding APT option, Apt::Protect-Kernels, and you could disable that — but assuming you’re running a kernel matching the latest packages, 6.1.0-18, the headers package will still be protected.

Once that package is removed, the C compiler should become a candidate for auto-removal, and apt autoremove should remove most if not all of the remaining packages.

If that’s not the case, you might also need to tell autoremove (or autopurge) to ignore “Recommends” dependencies:

sudo apt -o Apt::AutoRemove::RecommendsImportant=false autopurge

Take care when running this — it will offer to remove all packages which are only kept to satisfy “Recommends”, which could well be more than the set of packages installed through virtualbox.

Setting RecommendsImportant to false breaks the symmetry with package installation, so it shouldn’t be set in apt’s configuration unless you also disable “Recommends” installation by default (Apt::Install-Recommends). For regular desktop use that’s usually not a good idea.

Answered By: Stephen Kitt
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.