If you run out of disk space, and you know you have installed Snap applications, open your folder snap - /var/lib/snapd/snaps(ubuntu / debian). Here you will notice that Snap keeps older versions of previously installed / uninstalled packages.
You can also find this out from the terminal:
snap list --all
Snap keeps 3 versions of each package, including the active version. You can change the number of versions using the following command: (value can be between 2 and 20)
sudo snap set system refresh.retain = 2
Popey, a developer at Canonical who works on Snapcraft and Ubuntu, has provided a simple script that can clean up old versions of Snap packages and keep the latest version.
#!/bin/bash
set -eu
snapsToRemove=$(LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $2, $3}')
while read snapname version revision; do
if [[ "$revision" == *[a-zA-z]* ]]; then
# Version field is empty. Revision is in second field
revision=$version
fi
snap remove "$snapname" --revision="$revision"
done <<< $snapsToRemove
Save the above script with the .sh extension (for example, snap_clean.sh), grant it executable permissions:
chmod + x snap_clean.sh
You can also remove the cache with sudo rm /var/lib/snapd/cache/*
Check the directory /var/lib/snapd/snaps/ before and after running this script. It should free up space.