I'm currently using a Ubuntu 20.04 machine with a small root volume. The default snap setup occupies ~1G space, though with only a few packages. And when I tried to remove core from snap I got the following error.

# snap remove core18 error: cannot remove "core18": snap "core18" is not removable: snap is being used by snaps gnome-3-34-1804, gtk-common-themes and snap-store. 

I understand I can work around the issue by manually remove the dependants first, but is there a one-liner solution that manages the dependencies automatically so that all snaps and snapd can be removed in one go?

7

2 Answers

A one-liner this is not but, if you would like to completely remove everything related to snaps on your machine, follow these steps:

  1. Open the Terminal

  2. List all the snaps installed on your system with snap list. You will see something like this:

    Name Version Rev Tracking Publisher Notes chromium 87.0.4280.141 1444 latest/stable canonical✓ - core 16-2.48.2 10583 latest/stable canonical✓ core core18 20201210 1944 latest/stable canonical✓ base emote 1.3.0 12 latest/stable tom-james-watson - gnome-3-28-1804 3.28.0-19-g98f9e67.98f9e67 145 latest/stable canonical✓ - gnome-3-34-1804 0+git.3556cb3 66 latest/stable canonical✓ - gnome-system-monitor 3.36.0-12-g35f88a56d7 148 latest/stable/… canonical✓ - gtk-common-themes 0.1-50-gf7627e4 1514 latest/stable/… canonical✓ - snap-store 3.38.0-59-g494f078 518 latest/stable/… canonical✓ - spotify 1.1.46.916.g416cacf1 43 latest/stable spotify✓ - vlc 3.0.11 1700 latest/stable videolan✓ - 
  3. Remove each snap that you may have chosen to install using sudo snap remove <package>:

    sudo snap remove chromium sudo snap remove emote sudo snap remove spotify sudo snap remove vlc 
  4. Remove the core snaps in this order (your list may be slightly different):

    sudo snap remove snap-store sudo snap remove gtk-common-themes sudo snap remove gnome-system-monitor sudo snap remove gnome-3-34-1804 sudo snap remove gnome-3-28-1804 sudo snap remove core18 sudo snap remove snapd 
  5. Verify there are no more snaps installed with snap list. You should see a message like this:

    No snaps are installed yet. Try 'snap install hello-world'. 
  6. Unmount the snap mount points with sudo umount /snap/core/{point}, replacing {point} with the actual mount point. You can find the complete list using df -h.

    Note: In Ubuntu 20.10 (and newer) you only need to do this: sudo umount /var/snap.

  7. Remove snapd from your system with sudo apt purge snapd

  8. Remove any snap-related directories that might remain:

    rm -rf ~/snap sudo rm -rf /snap sudo rm -rf /var/snap sudo rm -rf /var/lib/snapd 

Your system will now be devoid of snaps.

1

It's not a one-liner, but...

sudo snap remove $(snap list | awk '!/^Name|^core/ {print $1}') sudo apt remove --purge -y snapd gnome-software-plugin-snap 

I should add that removing snapd and gnome-software-plugin-snap1 remove also ubuntu-software, the Ubuntu software store. This can be fixed by

sudo at install gnome-software 

however the icons do not all come back...

3