How to remove recommended and suggested dependencies of uninstalled packages?

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


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


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.