Skip to content

Instantly share code, notes, and snippets.

@thetredev
Last active August 7, 2023 15:48
Show Gist options
  • Save thetredev/13f784831180e7430784e4091e1cda39 to your computer and use it in GitHub Desktop.
Save thetredev/13f784831180e7430784e4091e1cda39 to your computer and use it in GitHub Desktop.
Remove snap from Ubuntu

Remove snap from Ubuntu

Tested with:

  • Ubuntu Desktop 22.04.2
  • Ubuntu Server 22.04.2

Both are VirtualBox VMs on my Void Linux host. Both have been installed using the following options:

  • Normal installation (not minimal), to ensure it's fully bloated
  • With third party drivers

After the install, sudo apt update and sudo apt full-upgrade have been applied. A reboot was done next.

Removal Guide: Ubuntu Desktop

First list which snaps are installed:

$ sudo snap list
Name                       Version           Rev    Tracking         Publisher   Notes
bare                       1.0               5      latest/stable    canonical✓  base
core20                     20230126          1822   latest/stable    canonical✓  base
firefox                    110.0-3           2356   latest/stable/…  mozilla✓    -
gnome-3-38-2004            0+git.6f39565     119    latest/stable/…  canonical✓  -
gtk-common-themes          0.1-81-g442e511   1535   latest/stable/…  canonical✓  -
snap-store                 41.3-66-gfe1e325  638    latest/stable/…  canonical✓  -
snapd                      2.58.2            18357  latest/stable    canonical✓  snapd
snapd-desktop-integration  0.1               49     latest/stable/…  canonical✓  -

If we try to remove snapd right away, we get an error:

$ sudo snap remove snapd
error: cannot remove "snapd": snap "snapd" is not removable: remove all other snaps first

Let's remove all snaps in the correct order:

$ sudo snap remove snap-store
snap-store removed

$ sudo snap remove snapd-desktop-integration 
snapd-desktop-integration removed

$ sudo snap remove firefox
firefox removed

$ sudo snap remove gtk-common-themes 
gtk-common-themes removed

$ sudo snap remove gnome-3-38-2004 
gnome-3-38-2004 removed

$ sudo snap remove bare
bare removed

$ sudo snap remove core20
core20 removed

$ sudo snap remove snapd
snapd removed

After all snaps have been removed, we have to remove the snapd APT package as well:

$ sudo apt purge snapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  snapd*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 102 MB disk space will be freed.
Do you want to continue? [Y/n] 
(Reading database ... 201361 files and directories currently installed.)
Removing snapd (2.58+22.04) ...
Warning: Stopping snapd.service, but it can still be activated by:
  snapd.socket
Processing triggers for gnome-menus (3.36.0-1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for mailcap (3.70+nmu1ubuntu1) ...
Processing triggers for desktop-file-utils (0.26-1ubuntu3) ...
(Reading database ... 201265 files and directories currently installed.)
Purging configuration files for snapd (2.58+22.04) ...
rmdir: failed to remove '/etc/systemd/system/snapd.mounts.target.wants': No such file or directory
Discarding preserved snap namespaces
Final directory cleanup
Removing extra snap-confine apparmor rules
Removing snapd cache
Removing snapd state

Optional: Remove dangling dependencies, too:

$ sudo apt autoremove --purge
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

In my case there were none installed.

Reboot the system:

sudo systemctl reboot

If there's still a folder named snap lurking in your home directory, remove it as well:

rm -rf ~/snap

Now you're done!

If you want to install Firefox via APT like a sane person, don't do it! It will install the snap version instead. Either download the DEB file from https://www.mozilla.org/en-US/firefox/new or install the official PPA:

sudo add-apt-repository ppa:mozillateam/ppa
sudo apt install firefox-esr

Removal Guide: Ubuntu Server

First list which snaps are installed:

$ sudo snap list
Name    Version        Rev    Tracking       Publisher   Notes
core20  20230126       1822   latest/stable  canonical✓  base
lxd     5.0.2-838e1b2  24322  5.0/stable/…   canonical✓  -
snapd   2.58.2         18357  latest/stable  canonical✓  snapd

If we try to remove snapd right away, we get an error:

$ sudo snap remove snapd
error: cannot remove "snapd": snap "snapd" is not removable: remove all other snaps first

If you have custom snaps installed, be sure to remove those first.

Let's remove all snaps in the correct order:

$ sudo snap remove lxd
lxd removed

$ sudo snap remove core20
core20 removed

$ sudo snap remove snapd
snapd removed

After all snaps have been removed, we have to remove the snapd APT package as well:

$ sudo apt purge snapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  squashfs-tools
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
  snapd* ubuntu-server-minimal*
0 upgraded, 0 newly installed, 2 to remove and 0 not upgraded.
After this operation, 102 MB disk space will be freed.
Do you want to continue? [Y/n] 
(Reading database ... 73941 files and directories currently installed.)
Removing ubuntu-server-minimal (1.481) ...
Removing snapd (2.58+22.04) ...
Warning: Stopping snapd.service, but it can still be activated by:
  snapd.socket
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for man-db (2.10.2-1) ...
(Reading database ... 73841 files and directories currently installed.)
Purging configuration files for snapd (2.58+22.04) ...
rmdir: failed to remove '/etc/systemd/system/snapd.mounts.target.wants': No such file or directory
Discarding preserved snap namespaces
Final directory cleanup
Removing extra snap-confine apparmor rules
Removing snapd cache
Removing snapd state

Optional: Remove dangling dependencies, too:

$ sudo apt autoremove --purge
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  squashfs-tools*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 424 kB disk space will be freed.
Do you want to continue? [Y/n] 
(Reading database ... 73831 files and directories currently installed.)
Removing squashfs-tools (1:4.5-3build1) ...
Processing triggers for man-db (2.10.2-1) ...

squashfs-tools can be used for other things, so it's not necessary to remove it. It just acts as the storage engine for snapd.

Reboot the system:

sudo systemctl reboot

If there's still a folder named snap lurking in your home directory, remove it as well:

rm -rf ~/snap

Now you're done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment