Developer Notes

Reduce storage space used by Snap packages

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.”

https://snapcraft.io/about

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Articles

Want your website to turn up in Google Search results? You can submit your website for indexing in Google Search
Occasionally, we need to bring our website visitors to a maintenance page. Don't worry, you can spin up a Maintenance
When you are deploying changes to a WordPress website, you might encounter an error about PHP's upload_max_filesize. Here is one
After installing Android Studio in Ubuntu, you might experience getting a blank screen instead of the Android Studio Setup Wizard.
The Loop Grid widget allows you to set the total number of items to load and display in the Loop
When creating a page, always remember this: DESKTOP ➤ TABLET ➤ MOBILE. Responsive attributes you set for Desktop will reflect

Recent Articles

Topics

Related Topics