15

I have Ubuntu installed. I have a partitioned disk with a root / partition of 20 GB and a /home partition of 60 GB. I thought that this would be enough for Ubuntu, but snap is using a lot of storage space.

6,9 GiB [###       ] /snap                                                                                                                                                                                                                                          
5,8 GiB [###       ] /usr
3,9 GiB [##        ] /var
2,3 GiB [#         ] /opt

This is the /snap folder:

1,7 GiB   [##########] /gnome-3-34-1804                                                                                    
1,2 GiB   [#######   ] /gnome-3-28-1804
868,0 MiB [#####     ] /kde-frameworks-5-core18
721,7 MiB [####      ] /postman
653,2 MiB [###       ] /gtk-common-themes
594,0 MiB [###       ] /core
393,8 MiB [##        ] /core20
337,6 MiB [#         ] /core18
293,4 MiB [#         ] /snap-store
238,8 MiB [#         ] /snapd
39,6 MiB  [          ] /canonical-livepatch
4,0 KiB   [          ] /bin
4,0 KiB   [          ]  README

I'm not using KDE and it seems like it's an old version of GNOME. Can I just remove that?

Do you have any other ideas for making some space?

Harm
  • 251

2 Answers2

22

Do you have any other ideas for making some space?

Below there is a script (it is an extract from a personal script that I use to perform a general "spring cleaning" of the root partition) that reduces the overall size of snaps working in three directions:

  1. reduce the maximum numbers of revisions stored in your system (line snap set system refresh.retain=2 of the script)
  2. clean the oldest revisions when you have snap revisions that exceed the maximum number defined in the previous point (while loop in the script)
  3. Clean the snap cache directory (rm /var/lib/snapd/cache/* command in the script)
#!/bin/bash

Error status variables

STATUS_OK=0 STATUS_ERROR=1

Color settings

YELLOW_COLOR="\033[1;33m" RED_COLOR="\033[0;31m" OFF_COLOR="\033[0m"

Set English language

LANG=en_US.UTF-8

Execute it as root user

if [ "${USER}" != root ]; then echo -e "${RED_COLOR}ERROR: must be root! Exiting...${OFF_COLOR}" exit "${STATUS_ERROR}" fi

Current status

USED_BEFORE="$(df -k / | awk 'NR>1 {print $3}')"

snapd revisions clean

if [ -n "$(command -v snap)" ]; then

shellcheck disable=SC2162

read -p "→ Do you want to remove unused snapd revisions? [Y/n] " KEY KEY="${KEY:0:1}" && KEY="${KEY,,}" if [ "${KEY}" = "y" ] || [ "${KEY}" = "" ]; then # remove unused snapd revisions echo "Removing unused snapd revisions..." snap set system refresh.retain=2 # shellcheck disable=SC2162 snap list --all | awk '/disabled/ {print $1, $3}' | while read SNAP_NAME SNAP_REV; do snap remove "${SNAP_NAME}" --revision="${SNAP_REV}"; done if [ -d /var/lib/snapd/cache ] && [ -n "$(ls -A /var/lib/snapd/cache)" ]; then rm /var/lib/snapd/cache/* fi echo "Nothing unused to uninstall" else echo "Task skipped" fi fi

Current status

USED_AFTER="$(df -k / | awk 'NR>1 {print $3}')"

Summary

echo -e "${YELLOW_COLOR}Freed up space: $(( (USED_BEFORE - USED_AFTER)/1024 )) MB${OFF_COLOR}" exit "${STATUS_OK}"

  • Save the above code in a file, for example snap-cleanup.sh
  • Put it in a folder defined in $PATH, for example $HOME/.local/bin
  • Make it executable by chmod +x $HOME/.local/bin/snap-cleanup.sh
  • Call it by sudo bash $HOME/.local/bin/snap-cleanup.sh

As a general consideration, size is a weakeness of the snap format, because shared libraries/dependencies are "duplicated" inside every snap. What you can do, if this is really a problem for you, consists in using the .deb version of an application (from apt install) instead of the snap version.

You can also remove completely snapd, but consider that for the GNOME variant of Ubuntu the number of packages distributed as snap is increasing, and for some of them the decision has been taken not by Canonical but by the package distributor itself (for instance, Mozilla for firefox). In the future the removal of snapd may not be harmless.

Lorenz Keel
  • 9,511
1

I reckon 20 GB is not enough for Ubuntu Desktop these days - this will leave you with very little space for applications.

Snaps take a lot of space, and Gnome Desktop as well as several other applications are included as a snap by default.

I wouldn't recommend anything less than 100 GB for a desktop installation just to be sure, unless you want to spend additional time tinkering and optimizing your disk space.

And for your additional questions: Yes, you should be able to remove gnome-3-28-1804 and kde-frameworks-5-core18 without any issue.

Artur Meinild
  • 31,035