29

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).

user2809402
  • 391
  • 1
  • 3
  • 4
  • 1
    Could you instead say what is the package that do this? – Braiam Sep 28 '13 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. – user2809402 Oct 09 '13 at 18:48

4 Answers4

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).

Totor
  • 348
  • 2
  • 9
  • I wouldn't recommend not installing recommendations as they most of the time are *useful*. – Braiam Jan 03 '14 at 00:37
  • 3
    @Braiam This is not what the OP asked though. Your comment is for him, not for me. – Totor Jan 03 '14 at 00:40
  • I'm just saying that that's maybe overkill. – Braiam Jan 03 '14 at 00: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 03 '14 at 00:43
  • 5
    InstallRecommends: Because why install 5MB of stuff you want, when you could also install 1GB of stuff you don't want? – Mark K Cowan Jan 31 '17 at 18:56
16

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.

Rolf
  • 1,911
  • 1
  • 15
  • 12
  • 2
    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 03 '19 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.

Braiam
  • 66,947
  • 30
  • 177
  • 264
  • 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. – user2809402 Oct 09 '13 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). – user2809402 Oct 09 '13 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](http://askubuntu.com/q/138484/169736). You can also use the `--no-install-recommends`, but apt-get don't install suggested packages by default. – Braiam Oct 09 '13 at 18:46
  • @user2809402 you should also check http://askubuntu.com/q/244470/169736 – Braiam Oct 09 '13 at 18:52
  • Braiam- Thanks for the deborphan pointer. I will check it out. – user2809402 Oct 09 '13 at 20:10
  • 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](http://askubuntu.com/a/399078). – Totor Jan 03 '14 at 00:29
  • @Totor as it's said in my upvoted comment: *it prefers to keep packages installed rather than remove them*. I'm stating the reasons why it works that way. I'm dead sure that if a package has no more dependencies when you run `apt-get autoremove Z` the dependencies of Z will get uninstalled by default. Your answer is just overriding the behavior (I'm not saying that it's wrong, just that it doesn't explain the behind curtains of the current behavior). – Braiam Jan 03 '14 at 00:36
  • @Totor is said in my answer too "If any of the dependencies has some other previously installed packages that recommend/suggest them then apt would not remove them." – Braiam Jan 03 '14 at 00:40
  • @Braiam `apt-get don't install suggested packages by default.` I can't find documentation stating what the default is, but on Ubuntu server 16.04 it is definitely installing recommended packages. I believe suggested packages by default are not installed, but recommended packages are. – Nateowami Jun 13 '18 at 19:12
  • @Nateowami ? I don't get why are you saying this? Just run `grep APT::Install-Recommends /etc/apt/apt.conf.d/*` and `grep APT::Install-Suggests /etc/apt/apt.conf.d/*` and you will find out which are the defaults. – Braiam Jun 13 '18 at 19:35
  • 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 '18 at 19:40
  • @Rolf autoremove does takes package names. I recommend you to try it. – Braiam Mar 03 '19 at 22:25
  • @Braiam I took your suggestion and here is what I found out: it does however it will proceed to remove any package given but then proceed to autoremove all orphaned packages on the system, so basically `apt-get autoremove x` would be equivalent to `apt-get remove x` followed by `apt-get autoremove`. So you cannot specify which packages you want to "autoremove" – Rolf Mar 05 '19 at 18:48
-1

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

sudo apt-get autoremove --purge <Z>
Aditya
  • 13,256
  • 17
  • 64
  • 95
  • 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". – user2809402 Oct 09 '13 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 '18 at 19:51