2

I am looking for a way to remove snap packages that are no longer depended upon, similar to apt autopurge/apt autoremove for .deb/dpkg packages.

What does apt autoremove do?

It removes packages that were installed as dependencies, recommendations, or suggestions of other packages, but are no longer marked as such after an update, or because the original package has since been uninstalled.

But snap packages are dependencyless

Contrary to this common misconception, anyone who installs a common snap (eg. snap install firefox), will see that several other snaps are installed as its dependency, such as gtk-common-themes, gnome-<version>, core<version>, and others that are in turn dependencies of these.

So, this question has been incorrectly marked as a duplicate.

Just remove the snap

The question is not how to remove a snap, but how to remove all automatically installed ones that are no longer needed. Finding out which snaps are no longer depended on is non-trivial when there are hundreds of them installed.

P Varga
  • 328
  • No, apt autopurge removes packages that are no longer needed. I'm looking for the snap equivalent to that... removing snaps that were installed as dependencies but aren't needed anymore, eg. the depending snap was uninstalled, updated, etc. – P Varga May 15 '22 at 04:13
  • Snap packages do not have dependencies like deb packages.. All dependencies are included within the snap package itself and thus get removed when the main squashfs file is removed. The definition of snap says "Snaps are app packages for desktop, cloud and IoT that are easy to install, secure, cross-platform and dependency-free." – guiverc May 15 '22 at 04:30
  • 3
    @guiverc This is clearly incorrect, which you can see yourself if you install a snap, for example snap install firefox and it will also install gtk-common-themes, gnome-3-38-2004 or similar, core20 or core18, and bare. So the question stands – P Varga May 16 '22 at 01:44
  • 1
    Those are not dependencies which was a design purpose of snap packages. Yes it's easy to think of them that way (esp. if thinking in deb package terms) but they're not called dependencies. Snap packagers can implement everything internally; or build using shared/common packages to save disk space/resources... This can be seen in the file /snap/firefox/current/snap/snapcraft.yaml for firefox; but they're not dependencies (but plugs). The base is different; snap packages built for Ubuntu Core 16 will require core16.. but that's still an important plug called base. – guiverc May 16 '22 at 01:56
  • 3
    Regardless of terminology, after an update, people end up with several versions of core for example that no other snap needs any more, because it moved to core18, then core20, etc etc. So core16 will still be installed but unnecessarily. So the question is, how to remove these stale packages that are left behind? – P Varga May 16 '22 at 02:04
  • Probably this was you were looking for, snap list --all | awk '$6~"disabled"{print $1" --revision "$3}' | xargs -rn3 sudo snap remove – Pablo Bianchi May 26 '22 at 04:52
  • 1
    @PabloBianchi I think that removes disabled snaps and I'm looking to remove "unused" or "orphaned" ones. Unless that's the same thing, but I don't think so.. it looks like I have enabled but unused snaps for example gnome-3-38-2004 – P Varga May 28 '22 at 23:35
  • 1
    In other words, snapd doesn't track plugs/dependencies/prerequisites and users have to manually clean up the mess left behind by uninstalled snaps? – SArcher Jun 20 '22 at 18:13

0 Answers0