If you are an avid Linux user, regardless of whether you use it for work or for personal reasons, you are probably familiar with Snap. However, it might surprise you how much storage space Snap packages use. You will most likely find that your Snap packages use gigabytes upon gigabytes of storage.
To check the storage space used by Snap, you can run this command:
sudo du -sch /snap/
What are Snaps?
The Snapcraft website describes them perfectly:
“Snaps are app packages for desktop, cloud and IoT that are easy to install, secure, cross‐platform and dependency‐free.”
Many software companies have started using Snap because it makes releasing software for many Linux distros and flavors so much easier. In addition to distros and flavors, there are a myriad of dependency versions and combinations of versions. Because Snap is containerized, software creators get to avoid dependency hell.
Unused Snap packages
Run this command to list all of the Snap packages and package revisions installed in your Linux system:
sudo snap list --all
You might discover that you don’t need, or no longer need, some of these packages. To remove a package and all its revisions, you can run this command:
sudo snap remove mypackage
Don’t worry — if a particular package is a dependency of another package, the command will fail and you will see a warning.
Unnecessary Snap package revisions
You will also find that Snap keeps multiple revisions of packages, including the current active revision.
“The refresh.retain value can be a number between 2 and 20. The default is refresh.retain=3 on Ubuntu Core systems and refresh.retain=2 on classic Ubuntu systems, such as those running an Ubuntu LTS release.”
https://snapcraft.io/docs/keeping-snaps-up-to-date#heading–refresh-retain
Except in rare cases, you probably don’t need older revisions. You can remove a particular revision with this command:
sudo snap remove mypackage --revision=revisionnumber
If you want to set the Snap limit to 2 revisions, you can run this command:
sudo snap set system refresh.retain=2
Check storage space
Check your available storage space again and celebrate.