31

I know of How to remove an uninstalled package's dependencies? and I tried

apt-get autoremove

but that does not remove dependencies that are recommended/suggested by other packages.

That is, if I install a package X that recommends Y, but I do not install Y, and then I install package Z that depends on Y. and later I do

apt-get remove --auto-remove Z

then Y is not automatically removed even though nothing depends on it. (X "picked up" Y, even though it does not depend on it).

2
  • 1
    Could you instead say what is the package that do this?
    – Braiam
    Sep 28, 2013 at 20:22
  • There are many examples, so I tried to extract the essence of the problem in the above description. You are right that I should have also included a concrete example: Consider installation of texlive-full. It installs a lot of font packages, which are suggested (but not required) by many pre-existsing packages (I cannot remember precisely which, but I think pre-existing libreoffice or matplotlib or octave suggested these). So the problem is that "apt-get install texlive-full" followed by "apt-get remove --purge --auto-remove texlive-full" does not leave the system in the same original state. Oct 9, 2013 at 18:48

4 Answers 4

21

If you want to remove recommended packages from your system, even if there are still some installed packages recommending (or suggesting) them, put the following in the file /etc/apt/apt.conf.d/99_norecommends (create it):

APT::Install-Recommends "false";
APT::AutoRemove::RecommendsImportant "false";
APT::AutoRemove::SuggestsImportant "false";

The documentation for these options is here.

Then, the next apt run (try apt-get autoremove) should remove them all. If it doesn't, launch aptitude, and type g and g again.

This configuration also disables the automatic installation of recommended packages when using apt-get. For aptitude it can be done from the console GUI, menu Options > Preferences > "Install recommended packages automatically" (uncheck it).

5
  • I wouldn't recommend not installing recommendations as they most of the time are useful.
    – Braiam
    Jan 3, 2014 at 0:37
  • 3
    @Braiam This is not what the OP asked though. Your comment is for him, not for me.
    – Totor
    Jan 3, 2014 at 0:40
  • I'm just saying that that's maybe overkill.
    – Braiam
    Jan 3, 2014 at 0:40
  • 1
    @Braiam That's your POV. I live pretty well with InstallRecommends disabled. For the record, it was disabled by default until Debian Squeeze released, that is since February 2011 (don't know about Ubuntu). Furthermore, you may not need the same configuration on a server or a desktop setup.
    – Totor
    Jan 3, 2014 at 0:43
  • 5
    InstallRecommends: Because why install 5MB of stuff you want, when you could also install 1GB of stuff you don't want? Jan 31, 2017 at 18:56
18

Overriding APT options

Unlike dependencies, automatically installed "recommended" or "suggested" packages may be ignored by apt-get autoremove.

As described elsewhere, this behavior of APT can be changed in the configuration.

Likewise, the configuration of the apt-get command can be temporarily changed through the -o command line option.

This is, how you would force autoremove to remove left-over "recommended" and "suggested" packages, in addition to unused dependencies.

sudo apt-get autoremove -o APT::Autoremove::RecommendsImportant=0 -o APT::Autoremove::SuggestsImportant=0

Caution!

Some functionality may be lost. Be prepared to investigate and reinstall things. It may be easier to leave these packages alone.

Other options

To uninstall the 'recommended' and 'suggested' packages solely for a particular package, have a look at the apt history log.

1
  • 3
    to simply analyze such packages, perform a dry run with apt-get's -s option and pipe to grep ^Remv — so that's the command: apt-get autoremove -s -o APT::Autoremove::RecommendsImportant=0 -o APT::Autoremove::SuggestsImportant=0 | grep ^Remv
    – myrdd
    Mar 3, 2019 at 21:53
2

Actually the command is:

sudo apt-get autoremove <Z>

But this has a trick! If any of the dependencies has some other previously installed packages that recommend/suggest them then apt would not remove them.

You didn't specified what package was but for example, if I were to install the IcedTea plugin, it would install Java/OpenJRE by dependencies. If I uninstall them using sudo apt-get autoremove icedtea-7-plugin you would notice that it won't remove Java/OpenJRE, since LibreOffice also suggests the packages.

So, to remove them you has to be overly specific about the package you wants to uninstall that normal autoremove won't:

sudo apt-get autoremove <Z> <dependency of Z>

This way you could be sure your package get removed.

You can also use deborphan to remove some dependencies.

13
  • 1
    By the way, my understanding from the apt manpage is that autoremove does not expect a package name, and will simply clean all un-needed package dependencies in the system. So you would have to do 2 steps: "apt-get remove Z" followed by "apt-get autoremove". These 2 steps can be done at once with "apt-get remove --auto-remove Z", as mentioned in my original question. But like I said, the problem is that there are some leftover packages which are not removed if they were suggested by something else. Oct 9, 2013 at 18:26
  • 2
    Yes, you described my problem perfectly. Thank you. But, unfortunately, you have not solved it, because I do not want to go to /var/log/apt/history.log and look for all the packages Y that where installed a couple of months ago with Z (in your example, Y=java/jre, Z=icedtea plugin) and then manually add all of them to the apt command line. I want to only specify Z, and the rest of the dependencies to be picked up automatically, even if they are suggested by another existing package X (X=libreoffice in your example). Oct 9, 2013 at 18:29
  • 1
    Unfortunately,this is the way the apt system works, it prefers to keep packages installed rather than remove them, even if they are not needed anymore. The only way to remove them is manually or with deborphan but deborphan may miss some packages still. You can use the Debug:: options and also check my other answer about this. You can also use the --no-install-recommends, but apt-get don't install suggested packages by default.
    – Braiam
    Oct 9, 2013 at 18:46
  • 1
    You're stating the obvious: if you uninstall them by hand one by one, then yes, you will get rid of them; but the OP is complaining because: "Y is not automatically removed". See my answer.
    – Totor
    Jan 3, 2014 at 0:29
  • 1
    @Braiam I tried that and was surprised to get no output whatsoever. apt-config dump | grep -i APT::Install-Recommends shows Install-Recommends is enabled (1) and APT::Install-Suggests is disabled (0).
    – Nateowami
    Jun 13, 2018 at 19:40
0

Right, if you want to remove package <Z> with dependances just type:

sudo apt-get autoremove --purge <Z>
2
  • 4
    Thanks, but unfortunately, adding "--purge" simply removes the configurations of packages that are removed with "autoremove". But as far as I can see, it does not change the decision about which packages to remove. That is, dependencies of Z which are suggested by some pre-existing package X, are still not removed, whether or not I specify "--purge". Oct 9, 2013 at 18:37
  • 1
    Also, autoremove works system-wide. So anytime you call autoremove, it will remove all unused packages on your system. Installing a package, then autoremoving will usually not return the system to the same state, and will instead leave a bunch of "leftover" packages.
    – Rolf
    Jan 29, 2018 at 19:51

You must log in to answer this question.

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