How to remove uninstalled snaps from cache?

When I install a snap with snap install <SNAPNAME> then it is being downloaded and mounted. When I remove it with snap remove <SNAPNAME> then 'everything' is being deleted like the snap, user settings dependecies and so on. But when I re-install the snap after removing it, it has no download time so the snap must be stored somewhere.

How can I clear the cache of snapd with all uninstalled snaps?


Solution 1:

You can remove the files in /var/lib/snapd/cache without issue. Also there is no need to stop snapd before.

This was answered in Snapcraft forum:

The answers boil down to: you should not have a lot of files with hardlink count 1; at most 5 in the default install. If you have more than that, it’s a bug, please let us know.

And yes you can remove them without issue; no need to stop snapd.

Here the command to do that:

sudo rm -rf /var/lib/snapd/cache/*

Solution 2:

You can also simply do:

sudo snap remove --purge $PACKAGE