Running low on disk space in Ubuntu can be frustrating, especially if you’re working with a small partition. A common culprit for this problem is the accumulation of old Snap revisions. If you find yourself short on space, before uninstalling applications or clearing caches, consider checking your Snap backups.
Recently, I noticed that my 40GB Ubuntu partition was almost full, and the usual methods to free up space weren’t enough. After running sudo du -sh /var/lib/snapd, I discovered that over 8GB was being used by outdated Snap versions—backups for each installed Snap, which were taking up space "just in case" a rollback was needed.
While it’s good to have backups for easy rollbacks, especially in environments like IoT or edge computing, they can become quite hefty. Personally, having 8GB of backups on my already cramped laptop felt excessive.
Understanding Snap Revisions
Snapd retains two versions of every installed Snap, regardless of whether it’s an app, core, runtime, or driver. This feature ensures that if an update causes issues, you can quickly revert to the previous version. However, if you’re confident in your current version’s stability, you might want to consider cleaning these old revisions to reclaim space.
While bash scripts for automatically removing unused Snap revisions exist, they indiscriminately delete all backups, which may not be ideal. A more controlled manual removal allows you to selectively keep critical versions.
Checking Disk Usage
To overview the installed snaps and their revisions, run this command in your terminal:
sudo snap list --all
This command will provide a detailed list of your installed Snaps, along with their revision numbers. However, if you’re concerned about how much space they’re occupying, you can check the total Snap usage with:
sudo du -sh /var/lib/snapd
Alternatively, using the Disk Usage Analyser may provide a visual representation of Snap sizes and the dates of disabled versions, helping you assess which to remove.
Removing Old Snap Revisions
Once you’ve identified the old Snap revisions you wish to remove, use the following command in your terminal, making sure to replace snap-name and revision-number with the appropriate values from your earlier command:
sudo snap remove --revision=<revision-number> <snap-name>
Be careful to verify the revision number before proceeding, as there are no prompts for confirmation. It may be helpful to use two terminal windows to cross-check your entries.
Temporary Solution
It’s important to note that this cleanup isn’t a one-time fix. As you continue to use Snap packages, old versions will accumulate again, necessitating regular maintenance. However, performing this task will free significant space and keep your system running smoothly.
If this guide helped you, please share your thoughts in the comments.
