Keep only the latest version of specific snap

Snaps are eating 3 Gb and I suspect that Android Studio is responsible. snapd keeps 3 last versions of every snap by default. Is it possible to tell it to keep only 1 for this specific snap?

$ snap list --all
Name                  Version                           Rev   Tracking   Publisher     Notes
android-studio                           53    stable     snapcrafters  classic
android-studio                           51    stable     snapcrafters  disabled,classic
android-studio                           47    stable     snapcrafters  disabled,classic

Snaps have automated/manual roll-back support (see snap revert) and also update through binary deltas. Both requires that you always have at least two versions on disk.

There have been discussions in the past to allow configuration to limit the on-disk install to two versions, but i do not know where that stands.

1 Like

For now, I am removing snaps files manually after inspecting with snap list --all:

$ snap remove android-studio --revision=53

Were there any changes to keep only one version of the snap? The space for snaps is basically multiplied after few refreshes. Even with no heavy apps, extra copy of multipass + core + gnome eats 500Mb extra.

Is there a problem that snap revert can not revert to remote version in repository?

To list top 30 snap that take the most space.

du -hcs /var/lib/snapd/snaps/* | sort -h -r | head -n 30

there is:

snap set system refresh.retain=N

where N can be 2 or greater (not 1 though)


With N=1 I could mark this as a solution. I will have to add a rule BleachBit to clean up duplicate snaps.

No snap revert specifically only allows reverting to local revisions you have installed and available to revert to.

Why it is not possible to revert to any revision from repository?

Because you need to have the snap revision available to revert to, and the snap store only allows downloading the most recent revision from a published channel/track, so if you don’t have that revision locally, you wouldn’t be able to revert to it.

It also doesn’t really match the use-case of snap revert, which is that if your snap got refreshed and it is broken, you would immediately notice and revert back to a working one, and then snap revert keeps you on that old revision until there is a revision available which is newer than the one you reverted away from.

Not long ago I could download any revision from the snap store.

It doesn’t seem practical to store a whole snap while could be a binary diff, or just a hash reference (such as IPFS).

This only works when you are the publisher of the snap, you cannot do this for arbitrary snaps.

1 Like