I use Ubuntu for 12 years, and snap in the recent releases of Ubuntu is really disgrace. It creates lots of problems. After an upgrade, Chromium does not start with the 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 the 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 have not 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.


In Ubuntu 20.04 LTS and Ubuntu 20.10, I removed snapd following this 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

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

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

I'm agree with you about snaps.

At the end I've completly removed snaps from my system by:

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 substitude snap programs with their APT / or .deb file version when available. Unfortunately In my case I've lost 1 application that I need but is the price I had to pay, but I gained less occupied disk space and slight time gain during boot.

gnome is yet installed and works regularly as before

enter image description here