100

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?

neun24
  • 1,619
Emil Engler
  • 1,258

3 Answers3

133

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 sh -c 'rm -rf /var/lib/snapd/cache/*'
knittl
  • 1,162
neun24
  • 1,619
40

Also note that snap not only keeps removed snaps, but also up to 20 older versions of that snap (standard is 3 versions). So for me, cleaning up those remaining copies resulted in far more reclaimed storage than cleaning the cache (5GB vs 1GB). This website has a nice script which I used for that:

#!/bin/bash
#Removes old revisions of snaps
#CLOSE ALL SNAPS BEFORE RUNNING THIS
set -eu
LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
        sudo snap remove "$snapname" --revision="$revision"
    done
bjrne
  • 502
4

If you have not uninstalled the package and you don't care about settings, you can also simply do:

sudo snap remove --purge $PACKAGE