I'm newbiew with snap usage, I have few apps installed on my system, something that I notice when run the command df -h I found mounted different versions of the same snap

/dev/loop0       143M   143M     0 100% /var/lib/snapd/snap/gravit-designer/7
/dev/loop1        82M    82M     0 100% /var/lib/snapd/snap/core/4110
/dev/loop7       198M   198M     0 100% /var/lib/snapd/snap/polarr/3
/dev/loop2        82M    82M     0 100% /var/lib/snapd/snap/core/4206
/dev/loop3       143M   143M     0 100% /var/lib/snapd/snap/gravit-designer/6
/dev/loop10      137M   137M     0 100% /var/lib/snapd/snap/gravit-designer/5

my question is why they keep there, the only way I found to remove the old is remove and install again the snap, there's something like prune to maintain my system?


Here's a short script which will remove all old versions of snaps. This will only keep the current active version, which should recover you some disk space.

# Removes old revisions of snaps
set -eu

snap list --all | awk '/disabled/{print $1, $3}' |
    while read snapname revision; do
        snap remove "$snapname" --revision="$revision"
  • It successfully removed all old versions, but no space is added to my disk! – mtoloo Jul 25 '18 at 15:15
  • Check dir /var/lib/snapd/snaps/ before and after running this script. Should have free up some space - if really removed some snaps. It should show messages like snap-name removed, eg gtk-common-themes removed. – PeterM Sep 24 '18 at 18:30
  • Excellent script! – Oliver Oct 26 '18 at 17:18

Starting from snap 2.34 and later, You can set the maximum number of a snap’s revisions stored by the system by setting a refresh.retain option.

$ sudo snap set system refresh.retain=2 

The refresh.retain value can only be a number between 2 and 20 and has a default value of 3

  • after doing this, moving from the default 3 to a new setting of 2, when are the current versions purged? – Tim Richardson Nov 14 '18 at 23:36
  • I think the old snaps will be purged when new version installed. As you may already know, snap updates installed apps automatically depending on refresh.timer option, so you don't have to do the update manually – Mustapha Hadid Nov 15 '18 at 6:12

The snapd docs on versions state that the outdated revisions should be automatically removed so that no more than the last two revisions are installed. However, I also saw more than two versions of my snaps installed.

You can list all the revisions with snap list --all to see something like:

Name     Version                  Rev   Tracking  Developer  Notes
core     16-2.31.2                4206  stable    canonical  core,disabled
core     16-2.32.3                4407  stable    canonical  core,disabled
core     16-2.32.5                4486  stable    canonical  core
spotify  5     stable    spotify    disabled
spotify  6     stable    spotify    disabled
spotify  13    stable    spotify    -

You can remove individual revisions with snap remove spotify --revision=5.

This is safe even for the disabled revisions of core and other dependencies, and snap remove with an explicit --revision=... even prevents you from removing non-disabled snaps.


A version of the script from another answer, as a one-liner, without the awk dependency:

snap list --all | while read snapname ver rev trk pub notes; do if [[ $notes = *disabled* ]]; then snap remove "$snapname" --revision="$rev"; fi; done

This likely requires bash or a compatible shell with the [[ construct.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.