149

How do I remove snap? apt pretends it's not there, but I can still call commands with it.

Trying to remove it says read only file system

# apt remove snap
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'snap' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
# snap whoami
email: -
BeastOfCaerbannog
  • 12,964
  • 10
  • 49
  • 77
quantumpotato
  • 1,593
  • 2
  • 8
  • 7

5 Answers5

179

The package is not called snap, but instead is snapd.

You will want to do

sudo apt autoremove --purge snapd

After that, run the following command so that Ubuntu does not automatically install snapd as an update.

sudo apt-mark hold snapd

Additional comments:

  1. Ubuntu 22.04 has Firefox as a snap app, as a part of the default installation. If you try sudo apt install firefox, it will reinstall snap without asking you. Follow this answer to install Firefox as an apt package.

  2. Also, since removing snap will also remove snap-store, you may want to install gnome-software as a GUI app store.

    sudo apt install gnome-software --no-install-recommends
    

--no-install-recommends ensures that it will not pull snap plugin once again.

  1. To prevent Ubuntu from automatically reinstalling snapd in future, see this answer
Archisman Panigrahi
  • 25,210
  • 17
  • 90
  • 185
dobey
  • 40,344
  • 5
  • 56
  • 98
  • 4
    Why `--purge`? The OP didn't say the removal must also remove the configs. – Ruslan May 14 '18 at 10:44
  • 35
    @Ruslan If the configs are left, apparmor crashes on startup in this case. – Charles Green Feb 22 '19 at 20:52
  • 1
    Will this prevent future system updates? Oftentimes the `ubuntu-desktop` meta-package gets deleted for things like this and you are forced to re-install it later on if you want to upgrade. Will that be the case here? – tutuca Nov 17 '19 at 03:26
  • 2
    Removal of a metapackage does not prevent updating of packages which it originally installed, no. – dobey Nov 17 '19 at 15:41
  • 1
    WATCH OUT: I did this to uninstall wechat, but it also automatically deleted skype, slack, spotify, and a lot of other gnome features! – pietro Mar 06 '20 at 10:43
  • 6
    @pietro This is not for removing individual snaps, but to remove all snaps and support thereof, from the system. If you want to remove individual snaps, you need to do so with `snap remove` instead. – dobey Mar 06 '20 at 15:35
  • 1
    @dobey yes you're right, I realized that only later. What I meant to say with my comment is that if you use the code that you (correctly) suggested, then watch out because it might have unintended consequences. I didn't know that slack, spotify, etc on my machine were installed with snap – pietro Mar 06 '20 at 16:12
  • It's important to note that this will only remove snaps in the present moment. Dependencies might pull it in automatically in future apt operations (apt does tell you and prompt you but apparently nobody reads that). If you want snaps to never reappear again, you must tell apt that using [apt_preferences(5)](http://manpages.ubuntu.com/manpages/focal/en/man5/apt_preferences.5.html). Maybe someone can test and provide the exact solution for that on this page? – Robie Basak Jun 30 '20 at 02:41
  • 1
    You may want to add `sudo apt-mark hold snapd` to make sure it doesn't inadvertently come back. – mivk Mar 28 '21 at 21:04
  • lxd user may need to be deleted also. – Konchog Sep 06 '22 at 10:25
  • You may also want to remove `/snap/bin` from your PATH. It is hardcoded in `/etc/environment` and `/etc/sudoers`. – nyg Nov 20 '22 at 13:36
126

TL;DR:

sudo rm -rf /var/cache/snapd/

sudo apt autoremove --purge snapd gnome-software-plugin-snap

rm -fr ~/snap

sudo apt-mark hold snapd

This will completely remove snap, snapd, all installed snap packages and their data, and never again suggest snap packages in the software store. Finally, it will block snapd package from ever being installed again.

Your output of mount, df and cat /proc/partitions will thank you ;)

Optionally

Test that the block works by trying to install the chromium-browser, which (at the time of writing) suddenly depends on the snapd and will drag everything just uninstalled back into your system upon installation:

sudo apt-get install chromium-browser

The installation should fail.

Stiin
  • 472
  • 5
  • 10
Stephan Henningsen
  • 4,771
  • 4
  • 16
  • 22
12

I'm not sure if you asked especially for this, but if you just want to remove showing snap packages in Software (gnome-software; as I wanted to), you can just uninstall snap plugin with command

sudo apt-get remove --purge gnome-software-plugin-snap

I don't know if --purge is necessary, but it works fine - Software doesn't show now packages from Snap Store, but I can still install them by command line with snap install [something]

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
Garbulix
  • 149
  • 7
9

I have just installed a server and apparently it also comes pre-installed with snaps that besides being useless are also blocking the shutdown of the device.

This very good blog post has instructions for cleaning up your system. It basically says:

snap list
sudo snap remove each_item # (by dependency order)
sudo umount /snap/core/xxxx # On 20.04, on 20.10 /var/snap
sudo apt purge snapd

Clear various files at /home/*/snap, /usr/lib/snap and alike

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

In case of the server the only snap was lxd (something Canonical is pushing as an alternative to docker).

IMHO this a bit of a conflict of interest between Canonical and the users. Users should be able to opt-in whatever they need and not be forced to uninstall stuff the hard way.

In any case, at least for the moment this is reversible. You can remove specific packages and the snap daemon and install later if needed.

Zanna
  • 69,223
  • 56
  • 216
  • 327
QT-1
  • 1,282
  • 12
  • 12
  • The blog instructions might work if you've got a clean system, but don't work if you've installed a snap yourself. Some of the snap items can't be removed. – EML Feb 24 '22 at 15:07
  • The key in to remove each_item # (by dependency order). You can try removing all packages then repeat for the ones that had dependencies. Probably will be done in a couple of iterations. – QT-1 Mar 23 '22 at 02:33
-2

if you want to remove snap store then you have to execute the following command in terminal:

sudo apt autoremove snapd
Parsa Mousavi
  • 3,197
  • 15
  • 35
MeHeDi HaSaN
  • 499
  • 1
  • 4
  • 6
  • 6
    This is very similar to [dobey's answer](https://askubuntu.com/a/1035917/22949). The difference is that [conffiles](https://www.debian.org/doc/manuals/maint-guide/dother.en.html#conffiles) are removed when `--purge` is passed (as in that answer), but not when the `autoremove` action is used without `--purge` (as in this answer). So this is not the same as that answer, but if there's a particular reason you recommend keeping them (even if it is that their removal is typically unnecessary) then you may want to [edit] this to explain that. – Eliah Kagan Jun 24 '20 at 16:43