8

I've just realised I'm not sure how to perform a purge with Apt, that will purge all the dependencies too. I'm reading here and there and still unsure have these candidates:

apt purge --auto-remove <packagename>

and (after purging some packages first):

apt autoremove --purge

Are they correct? Equivalent? Is there a better way?

0

2 Answers 2

17

They’re both correct, but not quite equivalent.

apt purge --auto-remove <packagename>

purges packagename and any packages which are rendered unnecessary by its removal, as well as any other packages which aren’t necessary.

apt autoremove --purge

purges any packages which aren’t necessary (marked as “automatically installed” and with no dependent packages).

The first form is what you’d use when manipulating individual packages; the latter is a clean-up operation across all packages.

You could also enable APT::Get::AutomaticRemove in your apt configuration to get apt to always auto-remove (or use aptitude which behaves like that by default).

2
  • The second form apt autoremove --purge will remove AND purge dependencies, while apt autoremove will remove dependencies but NOT purge them, is that correct? Commented Apr 21 at 14:17
  • 1
    That‘s correct. Commented Apr 21 at 14:53
0

The OP's suggested commands and the existing answer are correct, particularly according to the man page, but it turns out apt's behaviour is slightly more flexible than the documentation suggests.

To make the command line more concise when removing a package and its automatically installed dependencies, you can supply a package name to the autoremove command, as in apt autoremove <pkg>, in which case it behaves as apt remove --autoremove <pkg>. Thus, apt autoremove --purge <pkg> and apt purge --autoremove <pkg> both produce the same result.

Going further, apt autopurge <pkg> behaves in the same way as the canonical form apt remove --purge --autoremove <pkg>, and seems to be the most concise way to achieve recursive purging.

Whether or not to document this behaviour has apparently been controversial among the developers.

You must log in to answer this question.