On Debian I can use apt-get autoremove to remove packages that are no longer needed, i.e., that are not a dependency of any "manually installed" package. However, this does not remove packages that are merely "suggested" or "recommended" by manually installed packages. How can I find out the list of such packages on my system?


You can also tell apt-get autoremove to ignore “Recommends” and “Suggests”:

sudo apt-get autoremove -o Apt::AutoRemove::RecommendsImportant=false -o Apt::AutoRemove::SuggestsImportant=false

Use -s to get a list of the removals this would lead to without actually changing anything:

sudo apt-get autoremove -s -o Apt::AutoRemove::RecommendsImportant=false -o Apt::AutoRemove::SuggestsImportant=false
  • Thanks a lot! I think this is a much better solution than the one I proposed. Somehow, though, this does not return the same set of packages (it mostly returns more, but it also misses a few that deborphan found). – a3nm Oct 10 '17 at 9:45
  • The difference in output should be explained by your manual selections: deborphan ignores those, so it will find packages you no longer need but that are marked as manually installed. Basically that means you need to periodically review the output of apt-mark showmanual and mark packages you don’t explicitly need as automatically installed; then if they are in practice no longer necessary, autoremove will suggest their removal. – Stephen Kitt Oct 10 '17 at 11:16
  • Sure, thanks! (In fact, I already have scripts that periodically compare how apt-mark showmanual differs from a list that I maintain separately.) However, my point was that the output of your method is not the same as the output of my method even when I take the output of deborphan and specifically remove the manually installed packages (as per the command that I suggested). So I guess there must be some difference in how these two commands compute their output. – a3nm Oct 10 '17 at 11:38
  • Ah, OK, I see! I’m mostly curious about the extra packages which deborphan finds. Perhaps they match the auto-removal configuration in /etc/apt/apt.conf.d/01autoremove*... – Stephen Kitt Oct 10 '17 at 11:43
  • Here's the list, along with the aptitude why of each package: zero.crans.org/… – a3nm Oct 10 '17 at 11:52

This can be done using the deborphan -n command, or deborphan -an, but paying attention to the fact that this does not seem to really exclude manually installed packages (see here), so they have to be filtered separately. I use:

comm -3 -1 <(apt-mark showmanual | sort) <(deborphan -na | awk '{print $2}' | cut -d':' -f1 | sort)

See also another solution in a related question.

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.