Completely remove snap (and prevent it from ever installing)

I hope it's fine to post this, despite being in a community for an Ubuntu flavour. Snaps are Canonical's package format and deployment system, which I suppose we're already aware of. There are certain valid reasons why dislike snap though I don't see the need to tackle that on this post. Don't get me wrong though, they work just fine for me, I'm just more comfy with .deb packages.

For this very instance, I've made this script following my recent installation:

#!/bin/sh

# Remove snap packages (some need to be removed prior certain packages)
sudo snap remove --purge firefox
sudo snap remove --purge gnome-42-2204
sudo snap remove --purge gtk-common-themes
sudo snap remove --purge firmware-updater
sudo snap remove --purge bare
sudo snap remove --purge snapd-desktop-integration
sudo snap remove --purge core22
sudo snap remove --purge snapd

# Disable running services (this can be masked further)
sudo systemctl disable snapd.socket
sudo systemctl disable snapd.service
sudo systemctl disable snapd.seeded.service
sudo systemctl disable snapd
sudo systemctl mask snapd

# Wipe some of the remnants
sudo rm -rf /var/cache/snapd/
rm -rf ~/snap

# Purge snap and mask it 
sudo apt autoremove snapd --purge -y
sudo apt-mark hold snapd

echo "\e[1;32m\nSnapd is successfully removed.\n"

To discuss about it briefly, the first section is used to remove snap packages. I'm very certain that this can be shortened to one line, though I can't remember what packages need to be removed before the others.

bare and core22 (core24 for Noble) are base packages that provides a runtime environment with the libraries and dependencies common to other snap packages. On the other hand, snapd is the daemon (or background service) that manages and maintains your snaps.

The second section will disable the snapd services. snapd.socket handles/kickstarts communications to the snapd daemon as;

Socket units may be used to implement on-demand starting of services, as well as parallelized starting of services.

Masking a service (similar to the last line of the section) will make it impossible for a service to be started, without unmasking it first. This mechanism is similar to the apt-mark hold which prevents snapd from ever installing (even when called as a dependency).


For installing the .deb Firefox, import the repo signing key first:

wget -q https://packages.mozilla.org/apt/repo-signing-key.gpg -O- | sudo tee /etc/apt/keyrings/packages.mozilla.org.asc > /dev/null

Add the Firefox repository afterwards (doesn't follow the deb822 format):

echo "deb [signed-by=/etc/apt/keyrings/packages.mozilla.org.asc] https://packages.mozilla.org/apt mozilla main" | sudo tee -a /etc/apt/sources.list.d/mozilla.list > /dev/null

Update the package list and install Firefox normally:

sudo apt update && sudo apt install firefox

For installing .deb Thunderbird, add their PPA repository, update and install. If you dislike PPAs, you can stick with their tarballs or Evolution (love it so far).

sudo add-apt-repository ppa:mozillateam/ppa
sudo apt update && sudo apt install thunderbird

For installing .deb Chromium, you can add the Linux Mint repos. I didn't add it here since adding a repo of another distro can create problems. Personally, I manually download and install it from their website, and update it manually. Won't suggest it to anyone, ever.

EDIT 1: In place of Chromium and Thunderbird, I suggest installing Vivaldi by downloading it from their website. This automatically adds their repository upon installation (and can be easily updated thru the package manager) unlike the previous one.


Usually, there's the need to create a preference file that would set package priority under /etc/apt. For this instance however, this isn't necessary anymore since snapd is already masked earlier.

As a little thank you for reading to this point, here's a simple cleanup script I've done! Can't say it's any good but I hope it's helpful at least.

#!/bin/sh

sudo apt-get autoremove --purge -y
sudo apt-get autoclean
sudo apt-get clean
sudo dpkg --configure -a
sudo journalctl --rotate
sudo journalctl --vacuum-time=1s
sudo rm -rf ~/var/cache/apt/
rm -rf ~/.cache/*

echo "\e[1;32m\nSystem cleanup done.\n"

You can install it through this Makefile (sudo make install). This makes it more convenient to call by simply running cs in the terminal.

PREFIX = /usr/bin

all:
	@echo Run \'make install\' to install cleansystem.

install:
	@mkdir -p $(PREFIX)
	@cp -p cs.sh $(PREFIX)/cs
	@chmod 755 $(PREFIX)/cs

uninstall:
	@rm -rf $(PREFIX)/cs
3 Likes

I am anti-snap.

However ... there are snap packages that, if removed, will create havoc on your system. I will let the experts spell out which "core" packages, and how they impact, if they are completely purged.

For those "core" packages, "tread lightly" as they say! :slight_smile:

1 Like

I can confirm, yeah. For instance, Pro and Livepatch is reliant on it. I suppose it is only intuitive to assume that snap packages and the daemon itself will be much tightly integrated to Ubuntu someday.

Thankfully, if you don't use those services or anything reliant on snap explicitly, it should work just as fine as it used to be. For now, that is. I can only hope this remains true for the years to come.

2 Likes