Why does removing a "metapackage" not remove the dependencies which it installed?

If I attempt to uninstall a metapackage, apt does not actually remove the metapackage's dependencies, only the "wrapper" itself. Even when running apt autoremove, these subpackages are not listed. I find it confusing that autoremove removes dependencies for most normal packages, but not many metapackages. Why is this?


Meta-packages are not magic in any regard: the concept "of meta-package" is not part of the APT system - a meta-package is simply a package which doesn't have actual content, just dependencies. So removing them has the same effect as removing a package with actual content that also depends on some other stuff, like a web server application module will require a web server, but when you remove it - the web server should still stay installed.

That being said, APT keeps track of which packages were automatically installed because another package requested them (like a meta-package requesting "actual" packages, or a web server application module requiring a web server), and once you remove the requiring package APT will suggest you run apt autoremove to get rid of such automatically installed packages.

The main problem with "meta-packages" as they are used in the Ubuntu operating system is that they depend on a lot of packages, essentially installing a huge selection of software with a single install. When installing so many packages, especially such that are very closely tied together - you can get a lot of cross-dependencies: the meta package requires packages A, B and C for you, but A also depends on B and B (maybe surprisingly) also depends on A. So if you remove the meta-package, only C will get removed.

As a concrete example, lets consider the LXDE meta-package lubuntu-desktop:

  • lubuntu-desktop requires lxqt-core
  • lxqt-core requires lxqt-panel
  • lxqt-panel depends on lxqt-core. Actually, this dependency is not Requires, but Recommends - but that should be enough for apt to decide not to automatically remove either package.

The following answers have more details:

  • https://unix.stackexchange.com/a/447957/4323
  • https://unix.stackexchange.com/a/265186/4323

ALL packages installed by the Ubuntu's ubiquity installer are apt-marked 'Manual' (instead of 'Auto), making all those packages ineligible for autoremoval.

You can still remove them, of course, you just cannot autoremove them.

The Ubuntu Server, Minimal Image, and Cloud Image installers are not based on ubiquity, and their packages are eligible for autoremoval.

If you are not familiar with apt-marking, it's simply how apt keeps track of which dependencies were specified by the admin ('Manual'), and which were pulled in as dependencies ('Auto'). See man apt-mark for more information about it.

The reason for the non-standard Ubiquity behavior is to protect you: Folks modify their desktop systems in all kinds of ways, including ways that require removal of the metapackage. Most users don't usually intend to remove their entire desktop, doing so unexpected can be a rather Significant Emotional Event, so the Ubuntu developers made the change to protect users from their own (unintended) folly. After all, Ubuntu is intended for new and unskilled users, too.

Folks who want to prune their packages to just what they actually use (we all have tried that at one time or another) will find it much easier to start from the Minimal Image and build up rather than fight the apt-marking to cut down.