Disabling Snap, and Keeping It Disabled

Snap apps tend to be slower, larger, weirder-looking, and buggier than their native counterparts, and regardless of whether or not they're ever actually run, their mere existence noticeably slows down the computer's overall start up and shut down times.

Snaps are, at least, optional, and can be removed.

But only temporarily.

Each and every time you upgrade to a new Ubuntu release, they'll get sneakily reinstalled, and you'll have to remove them all over again.

Thankfully, there is a workaround. You can disable snap, and keep it that way!

Remove All Snaps

First things first, if you have any individual snap apps installed, you'll need to remove them, and if you care to, replace them with non-snap alternatives.

To see the damage, run:

snap list

Unlike apt, snap doesn't support multi-app operations or automatic dependency management, so you have to remove each app one-at-a-time, working your way down from the top of the food chain.

In other words, you'll need to start by removing the main apps, the ones with recognizable names like firefox or gimp.

For each one, run:

sudo snap remove --purge THEAPP

Once you're down to the weirdly-named stuff, repeat the process. These can have dependencies too, so if you get an error, simply move onto the next entry and circle back at the end.

Anything named core* will probably need to be saved for last, and I don't think it is possible to remove the bare snap at all, so when all is said and done, snap list might still have that one item listed, but everything else should be gone.

Remove Snapd

With all the individual snaps gone, you can now safely remove the corresponding snapd daemon.

To be safe, you should manually stop and disable all of snapd's systemd services first:

# Stop.
sudo systemctl stop snapd.service
sudo systemctl stop snapd.socket
sudo systemctl stop snapd.seeded.service

# Disable.
sudo systemctl disable snapd.service
sudo systemctl disable snapd.socket
sudo systemctl disable snapd.seeded.service

And now you can uninstall the daemon the usual way:

sudo apt-get purge snapd

Even though we requested a "purge", the operation will probably leave all of the data associated with your snap apps behind. You can manually free up the space by removing those directories:

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

Keep Snapd Dead!

Now for the trick!

To keep Ubuntu from ever trying to reinstall snapd or snaps, we can leverage apt's preference system to cast such requests to the equivalent of /dev/null.

Simply run the following, all in one go:

cat <<EOF | sudo tee /etc/apt/preferences.d/nosnap.pref
# This file forbids snapd from ever being installed by APT.

Package: snapd
Pin: release a=*
Pin-Priority: -10
EOF

That's it!

A Subsequent Change of Heart

The you of tomorrow may want different things than the you of today. If you ever need to get snap back for any reason, simply reverse the steps:

# Remove the apt preference.
sudo rm /etc/apt/preferences.d/nosnap.pref

# Refresh apt and reinstall snapd.
sudo apt-get update
sudo apt-get install snapd

# Reinstall the individual snap(s).
sudo snap install WHATEVER
Josh Stoik
24 April 2023
Previous Re-rewriting JS Mate Poe in Rust/Wasm
Next Installing CUETools 2.2.4 on Linux via WINE