Ubuntu – Why isn’t `auto-remove’ removing all unnecessary dependencies

aptdpkgpackage-management

I just installed a package (dansguardian in this case) and apt told me that I had unmet dependencies.

# sudo apt-get install dansguardian
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  clamav clamav-base clamav-freshclam libclamav6 libtommath0
Suggested packages:
  clamav-docs squid libclamunrar6
The following NEW packages will be installed:
  clamav clamav-base clamav-freshclam dansguardian libclamav6 libtommath0
0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/4,956 kB of archives.
After this operation, 14.4 MB of additional disk space will be used.
Do you want to continue [Y/n]?

So I installed it and the dependencies. So far so good.

Later on, I decide that this package just isn't the package for me, so I want to remove it and all of the other junk it installed with it since I'm not going to be needing any of it:

# sudo apt-get remove --auto-remove --purge dansguardian
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  dansguardian
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 1,816 kB disk space will be freed.
Do you want to continue [Y/n]?

However it is only removing that one specific package. What about clamav clamav-base clamav-freshclam libclamav6 libtommath0? Not only did it not remove them, but clamav was actually running a daemon that loads every time the computer boots. I thought that --auto-remove would remove not only the packages, but also the dependencies that were installed with it.

So basically, without going through the apt history log file (if I even remember to do so, or if I even remember that a specific package I installed 3 months ago had dependencies along with it), is there a way to remove a package and all of the other dependencies that were installed like in this case?

Best Answer

As izx said, in his general answer, the first point, can be the cause of this sort of things.

Those dependencies are now also required/recommended by some other package(s) which are still installed on your system.

This is the most probable and valid reason for this kind of situation,But I am thinking that, the other packages named with clamav clamav-base clamav-freshclam libclamav6 libtommath0 most likely only associated with their mother package clamav. So, the first point, may not be the case in this particular situation.

The most likely cause of this problem, which seems to be the cause is, after installing the dansguardian package, you later installed all it's dependency packages by doing this kind of command below:

sudo apt-get install clamav clamav-base clamav-freshclam dansguardian libclamav6 libtommath0

If this is indeed the case, you can't uninstalled them by removing their mother package dansguardian. since in APT's language, they are installed "manually" as you explicitly installed these packages by feeding their name to the apt-get command, so must also uninstall them with explicitly stating their package name

You can check this, if it is the case by viewing /var/log/apt/history.log files.

To remove:

You must remove the installed packages by explicitly naming their name.So, in your specific situation it is

sudo apt-get purge clamav clamav-base clamav-freshclam dansguardian libclamav6 libtommath0

To see the dependent packages

You can find all the dependent packages with the below command:

apt-cache depends -i dansguardian | cut -f 2 -d ':' | tr '\n' ' '.

Note that, dansguardian depends on package libc6. while that package is very very essential one in your system. So, you can't remove all the dependency of dansguardian by generating their dependency package list with apt-cache command, hence it is not recommended. (actually, it is highly recommended to avoid doing that, unless you are happy with a broken system)

Related Question