183

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: -

6 Answers6

223

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
dobey
  • 41,650
145

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
  • 512
  • 5
  • 11
13

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
  • 17,371
Garbulix
  • 159
13

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
  • 72,312
QT-1
  • 1,742
2

I have a short script that removes all existing snaps and afterwards snapd can normally be removed.

#!/bin/bash

set -euo pipefail

snaps can only be removed if they have no other snaps

depending on them. We use a brute force approach and

just try to uninstall them multiple times.

try at most 30 times to uninstall all snaps

MAX_TRIES=30

for try in $(seq 1 $MAX_TRIES); do INSTALLED_SNAPS=$(snap list 2> /dev/null | grep -c ^Name || true) if (( $INSTALLED_SNAPS == 0 )); then echo "all snaps removed" exit 0 fi echo "Attempt $try of $MAX_TRIES to remove $INSTALLED_SNAPS snaps."

we ignore error during uninstall as we are retrying in the loop

snap list 2> /dev/null | grep -v ^Name | awk '{ print $1 }' | xargs -r -n1 snap remove || true done

echo "ERROR: Unable to uninstall" exit 1

reto
  • 121
0

A simple, clean and complete removal with a single line:

snap list | egrep -v 'base$|snapd$|Notes$' | awk '{print $1}' | xargs -I{} sudo snap remove {} --purge && sudo apt purge -y snapd && rm -rf ~/snap

Be mindful that it takes some time (usual snap behavior) an it is highly advisable not to interrupt the process by any means.