1

When I install packages via apt-get install <package> or aptitude install <package> and remove them afterwards with apt-get purge <package>; apt-get autoremove --purge, my system is not in the same state as before. It still has additional packages installed.

The additional packages are marked as automatically installed, as indicated by apt-mark showauto.

Namely this happens under Ubuntu 18.04 with g++-8, leaving cpp-8 gcc-8 libasan5:amd64 libcc1-0:amd64 libgcc-8-dev:amd64 libisl19:amd64 libmpc3:amd64 libmpfr6:amd64 libstdc++-8-dev:amd64 libubsan1:amd64. Is there a clean way to prevent this, in the sense of not having to parse APTs output?

4
  • What does aptitude why gcc-8 say? (I’m not trying to solve this particular instance, but I have a theory which I’d like to check before writing an answer.) – Stephen Kitt Oct 2 '19 at 16:00
  • The output is i g++-8 Depends gcc-8 (= 8.3.0-6ubuntu1~18.04.1). – philipp2100 Oct 3 '19 at 7:28
  • After removal it's i libxml2-dev Depends libicu-dev i A libicu-dev Depends libicu-le-hb-dev i A libicu-le-hb-dev Depends libharfbuzz-dev i A libharfbuzz-dev Depends libglib2.0-dev (>= 2.19.1) i A libglib2.0-dev Depends pkg-config i A pkg-config Depends dpkg-dev i A dpkg-dev Recommends gcc | c-compiler i A gcc-8 Provides c-compiler – philipp2100 Oct 3 '19 at 7:32
  • If I use aptitude remove/purge it works for g++-8, but the problem still occurs for g++. The output is the same as above, except with 7 instead of 8. – philipp2100 Oct 3 '19 at 8:42
2

The reason autoremove isn’t removing as much as you expect is that the packages which were installed automatically satisfy weak dependencies of other packages you already had installed. In your case, dpkg-dev is already installed, itself as an automatic dependency; because it recommends the virtual c-compiler package, any package providing c-compiler will be kept after it’s installed.

Put another way, you have package A already installed with a weak dependency on package B, and package B isn’t installed. If you later install package C, with a dependency (strong or weak, but taken into account by apt’s configuration) on package B, package B will also be installed, and marked as automatically installed. Removing package C however won’t cause package B to be considered for auto-removal, because package A keeps it “interesting” as far as apt is concerned.

You could ask autoremove to ignore weak dependencies (recommendations, by default), but that would probably cause a lot more packages to become removable than you’d expect or want.

I’m not aware of any good solution for this. aptitude is somewhat more agressive in its automatic removals, but it doesn’t handle all situations either.

See How do recommends and suggests interact with apt-get dist-upgrade and apt-get autoremove? and Why did 'apt-get autoremove' not work properly? for more on this.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.