40

I've been using Ubuntu for 12 years, and snap in the recent releases of Ubuntu is really a disgrace. It creates lots of problems. After an upgrade, Chromium does not start due to the following error:

chromium_chromium.desktop[122932]: snap-confine has elevated permissions and is not confined but should be. Refusing to continue to avoid permission escalation attacks: Operation not permitted

If a package changes configuration in a new version, it's its responsibility to make it work. Now, I have to reconfigure it after each start by

sudo apparmor_parser -r /etc/apparmor.d/*snap-confine*

How can I fully uninstall snap and re-install its packages by regular apt?

I don't have many packages handled by snap.

snap list
Name               Version             Rev   Tracking         Publisher   Notes
chromium           85.0.4183.121       1328  latest/stable    canonical✓  -
core18             20200724            1885  latest/stable    canonical✓  base
gnome-3-34-1804    0+git.3556cb3       60    latest/stable    canonical✓  -
gtk-common-themes  0.1-36-gc75f853     1506  latest/stable    canonical✓  -
snap-store         3.36.0-80-g208fd61  467   latest/stable/…  canonical✓  -
snapd              2.46.1              9279  latest/stable    canonical✓  snapd

My question is how to safely remove snap. From the snap list, I see gnome depends on snap.

Eduardo
  • 1,113
  • 1
  • 10
  • 26
Googlebot
  • 1,747
  • 9
  • 33
  • 55
  • 2
    On Ubuntu 20.04, the `apt install chromium-browser` will just re-install the *snap* package as that's where the program is now provided (has been for a few releases) – guiverc Oct 07 '20 at 06:34
  • Uninstalling `snap` (if there is a way) won't solve your problem. I had issues with chromium that was related to `snap`. My "solution" was to install Google chrome through Google's .deb package. I think that's your only option for chromium, at least. – Ray Oct 07 '20 at 06:50
  • Did you look at the snapcraft documentation? Because it clearly states how to remove snaps under the "Getting started" section. Also, this question has been asked before: [How to uninstall a snap package manually?](https://askubuntu.com/questions/1159280/how-to-uninstall-a-snap-package-manually) – Artur Meinild Oct 07 '20 at 07:35
  • Using `sudo snap remove` you can remove all snaps, and then you can remove snapd with `sudo apt remove` – Artur Meinild Oct 07 '20 at 07:38
  • 1
    @Ray I already have `Google Chrome`, but I want to have both browsers. In Linux communities, we are proud of open-source programs. It is a shame that Google Chrome works better than Chromium on Ubuntu. – Googlebot Oct 07 '20 at 11:45
  • 3
    Does this answer your question? [Is it still possible to install Chromium as a deb-package on 20.04 LTS using some third-party repository?](https://askubuntu.com/questions/1255692/is-it-still-possible-to-install-chromium-as-a-deb-package-on-20-04-lts-using-som) – N0rbert Oct 07 '20 at 13:44
  • @Googlebot Fair point. However, we can't take the statement "proud of open-source programs" for granted. In order to have these open-source programs, someone has to do it and these same people are you and me...we also have jobs that may or may not be separate. Some people have day jobs that don't overlap with any open source coding. So, we also have to be understandable when things aren't exactly as what we'd like. Unless we are willing to set aside our own time to help with that particular open source effort. I haven't followed the discussions behind `snap`...so I can't answer "why". – Ray Oct 08 '20 at 05:50
  • One important point in the OP's question hasn't been addressed: "From the snap list, I see gnome depends on snap." So when gnome is listed by `snap list`, can snapd be removed without breaking anything? – calocedrus Apr 22 '21 at 00:43
  • Note the new answer from Don Prince posted by Neil below. It covers absolutely everything and also installs Chromium, yes, real Chromium, from the last known valid Deb package and pins it in apt to ensure it doesn't get moved to snap again. – NeilG Jul 24 '21 at 01:51
  • Yes, snap causes problems, takes too much disk space and is not secure. I found this great article: "How to Remove Snap Apps & Block Them in Ubuntu 22.04" https://ubuntuhandbook.org/index.php/2022/04/remove-snap-block-ubuntu-2204/ Follow the instructions and completely block snap from being reinstalled. – Zen99 Apr 21 '22 at 22:08

3 Answers3

63

In Ubuntu 20.04 LTS (but it works also in the following releases till 22.04, that is the current one), I removed snapd following these steps:

# stop snapd services
sudo systemctl stop snapd && sudo systemctl disable snapd

# purge snapd
sudo apt purge snapd

# remove no longer needed folders
rm -rf ~/snap
sudo rm -rf /snap /var/snap /var/lib/snapd /var/cache/snapd /usr/lib/snapd /root/snap

Then, to avoid that other applications may reinstall it (chromium-browser is an example of application that restores snapd even if installed via apt) you can create a file no-snap.pref by issuing:

sudo -H gedit /etc/apt/preferences.d/no-snap.pref

and then copying the following content in it:

# To install snapd, specify its version with 'apt install snapd=VERSION'
# where VERSION is the version of the snapd package you want to install.
Package: snapd
Pin: release a=*
Pin-Priority: -10
Lorenz Keel
  • 8,362
  • 8
  • 36
  • 49
  • 3
    Brilliant, thank you. I've written this into a script: https://github.com/BryanDollery/remove-snap – Software Engineer Mar 21 '21 at 15:03
  • This script looks like it does it all: http://blog.pagefault-limited.co.uk/remove-snapd-from-ubuntu-kubuntu-20-04-and-restore-chromium-apt-deb-package – NeilG Jul 24 '21 at 00:59
  • 1
    On a recent 20.04 install on a VPS there was also `/root/snap/lxd`. – fdk1342 Feb 13 '22 at 17:44
  • Thanks for this guide. Unfortunately, I get an error message: Removing snap firefox and revision 2088 rm: cannot remove '/var/snap/firefox/common/host-hunspell/en_US.aff': Read-only file system .... dpkg: error processing package snapd (--purge): I don't know how to remove the remaining block device, even after reading https://forum.snapcraft.io/t/sdb5-mounted-on-firefox/31897 – Mario Dec 08 '22 at 08:35
  • A while ago, I've replaced firefox snap with firefox .deb. It seems to be an artifact of the linking from the snap sandbox/container to the root filesystem. For some reason `sudo snap remove firefox` was not able to disconnect this link... I can't see how to remove the link manually. – Mario Dec 08 '22 at 08:40
9

Full credit to Don Prince for a comprehensive and effective solution from this link

I recommend you run the commands individually. Some you won't need, and for some you may need one or two extra lines.

Run the exploratory informational commands listed in the comments to determine the specific situation in your install.

Also installs Deb packaged last known Chromium and pins it to prevent snapd taking over again in future. Awesome! Thanks Don!

#!/bin/bash

# probably best to manually type this commands individually checking for problems
 
# snap list | grep -v "^Name" | awk {'print "sudo snap remove " $1'}
 
sudo snap remove snap-store
sudo snap remove gtk-common-themes
sudo snap remove gnome-3-28-1804
sudo snap remove gnome-3-34-1804
sudo snap remove core18
sudo snap remove snapd
snap list # expect: No snaps are installed yet. Try 'snap install hello-world'.
 
sudo umount /run/snap/ns
 
sudo systemctl disable snapd.service
sudo systemctl disable snapd.socket
sudo systemctl disable snapd.seeded.service
sudo systemctl disable snapd.autoimport.service
sudo systemctl disable snapd.apparmor.service
 
sudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real
 
sudo systemctl start apparmor.service
 
# df | grep snap | awk {'print "sudo umount " $6'}
sudo umount /snap/chromium/1424
sudo umount /snap/gtk-common-themes/1514
sudo umount /snap/gnome-3-28-1804/145
sudo umount /snap/core18/1944
sudo umount /snap/snapd/10492
sudo umount /var/snap
 
sudo apt purge snapd
 
# find / -type d -iname '*snap*'
# (I left the kernel entries well alone)
rm -rf ~/snap
sudo rm -rf /snap /var/snap /var/lib/snapd /var/cache/snapd /usr/lib/snapd
sudo rm -rf /root/snap /root/snap/snap-store /usr/share/doc/libsnapd-glib1 /usr/share/doc/gir1.2-snapd-1
 
cat <<EOF | sudo tee /etc/apt/preferences.d/snapd
Package: snapd
Pin: origin *
Pin-Priority: -1
EOF
 
cat <<EOF | sudo tee /etc/apt/preferences.d/pin-xalt7x-chromium-deb-vaapi
Package: *
Pin: release o=LP-PPA-xalt7x-chromium-deb-vaapi
Pin-Priority: 1337
EOF
 
sudo add-apt-repository ppa:xalt7x/chromium-deb-vaapi
 
sudo apt update
sudo apt-get install chromium-browser
Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
NeilG
  • 191
  • 2
  • 6
5

I agree with you about snaps.

I have completely removed snaps from my system by doing this:

sudo apt-get purge snapd
rm -rf ~/snap                                      
sudo rm -rf /snap                                  
sudo rm -rf /var/snap                              
sudo rm -rf /var/lib/snapd 

Now the system works well Although I had to substitute snap programs with their APT or .deb file versions when available. Unfortunately in my case I've lost an application that I need but that's the price I had to pay, but I gained some disk space and my boot time is a little shorter.

gnome is still installed and works regularly as before

gnome shell version shown in terminal

Zanna
  • 69,223
  • 56
  • 216
  • 327
pat
  • 399
  • 1
  • 3
  • 12
  • 4
    `sudo apt purge snapd` accomplishes those last 3 `rm` operations for you, and does it in a future-proof way. – hobs Nov 21 '21 at 17:12