46

sudo apt-get install chromium-browser for some reason installs not a proper apt-get package but is installing the chromium snap.

I am aware that blocking such installs will not magically establish a maintained package, and would result in an installation failure. But I prefer to get error and install manually - from source or in unlikely cases from snap.

I want to never install anything using snap (for start, due to Snap Store closed-source practice). Especially not silently when I install using apt-get.

How can I disable snaps in gnome-software centre? is not answering my question as I want to get rid of snap infestation in apt - not in gnome-software-center.

muru
  • 197,895
  • 55
  • 485
  • 740
  • 1
    Look at this: https://askubuntu.com/q/1317194/1157519 – Levente Jun 12 '21 at 07:45
  • 4
    @Levente Thanks! Unfortunately it is not helping - I want installation to fail if it would require installing snap with apt-get. – reducing activity Jun 12 '21 at 07:55
  • 3
    The Chromium browser is not packaged as a deb and hasn't been for numerous releases (well before 20.04 anyway; 18.04 had it as a deb package but late 2018 it first appeared as snap - see https://discourse.ubuntu.com/t/please-test-chromium-snap-as-a-replacement-for-the-deb/7978 https://discourse.ubuntu.com/t/intent-to-provide-chromium-as-a-snap-only/5987 ; May-2018). It's available as deb only as stub so users don't get errors telling them package isn't found (it just loads the snap for them). I find discover is pretty easy to pick snaps and debs – guiverc Jun 12 '21 at 07:55
  • 5
    @guiverc I am fine with being unable to install Chromium with apt. In fact, if it requires snap - I want to be unable to do this. – reducing activity Jun 12 '21 at 07:57
  • I don't think what you're asking for is wise... You risk making your system unable to take updates.. which are often done via deb if it's technologically easier than getting users to run a command (and impossible via snap). – guiverc Jun 12 '21 at 08:00
  • 1
    @guiverc I am fine with that. If my system is unable to work without snap, I am OK with changing to a different distribution. – reducing activity Jun 12 '21 at 08:04
  • @guiverc I am not sure what code provided in https://askubuntu.com/questions/982112/how-can-i-disable-snaps-in-gnome-software-centre is actually doing, but it seems dubious that "you'll not see snaps in gnome or ubuntu software app" would also fix apt. – reducing activity Jun 12 '21 at 08:06
  • Lubuntu works well with snaps disabled (on boxes with only 1GB of RAM, it often makes sense to do so; though I tended to disable only, as there were times when I found it useful to enable it.. esp. upgrade time). I won't advise, but if you look Linux Mint is downstream of Ubuntu & only recently disabled/hacked-it so it did what you want, but problems soon appeared and parts of it had to be reversed... I don't think it's wise so won't help sorry (but disabling snaps is easier & what I'd recommend) – guiverc Jun 12 '21 at 08:08
  • Debian : No chromium snap https://packages.debian.org/sid/chromium .... Example Ubuntu 20.04 https://drive.google.com/drive/folders/1HsuZQNyKNq9L1XcE1clacFLwiRK9gDS3?usp=sharing – Knud Larsen Jun 12 '21 at 17:13
  • 3
    This is why I'm still on 18.04LTS, and will leave the Ubuntu world when it goes EOL. – RonJohn Jun 13 '21 at 07:21

2 Answers2

33

You have to remove snapd from the system by

sudo apt-get autopurge snapd

and then create special configuration file for APT, as LinuxMint did:

cat <<EOF | sudo tee /etc/apt/preferences.d/nosnap.pref
# To prevent repository packages from triggering the installation of Snap,
# this file forbids snapd from being installed by APT.
# For more information: https://linuxmint-user-guide.readthedocs.io/en/latest/snap.html

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

This will prevent Snaps installation in future.

N0rbert
  • 99,918
  • 1
    Is it safe to immediately perform the autopurge? Many tutorials involve first disabling snap, removing the individual snaps, etc. Perhaps yes, but this may then leave unused files and folders behind. – vanadium Jun 12 '21 at 09:40
  • 1
    The configuration script will do for us what is needed. – N0rbert Jun 12 '21 at 09:50
  • 1
    @N0rbert so by doing this, how do I install Firefox through apt? It depends on snapd – mslot Apr 23 '22 at 06:07
  • 2
    If you still want Firefox, first uninstall the Snap, then add the file above, then get Firefox from one of a few different places, as listed here: https://askubuntu.com/questions/1369159/how-to-remove-snap-completely-without-losing-firefox – jeffmcneill May 09 '22 at 07:24
  • I can't find evidence for the existence of an "autopurge" command. – odigity Aug 07 '23 at 18:11
  • 1
    @odigity The autopurge command exists for both apt-get and apt, and it's a shortcut for autoremove --purge. A piece of documentation about it was added to the apt source code in 2022: https://salsa.debian.org/apt-team/apt/-/blob/c9c1a1cb8471ff5cdb38b3c94cb96071370a091b/doc/apt-get.8.xml#L258 – jacobgkau Jan 05 '24 at 21:02
6

Besides setting files in /etc/apt, you can run apt-mark to prevent anything requiring snapd from installing, just after purge snapd:

$ sudo apt-mark hold snapd

For example, installing firefox in Ubuntu 22.04 (which is a snapd-based package) gives you an error:

$ sudo apt install firefox
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies: firefox : PreDepends: snapd but it is not going to be installed E: Unable to correct problems, you have held broken packages.

The only way to break this rule is to do it explicitly:

$ sudo apt install snapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  snapd
The following held packages will be changed:
  snapd
0 upgraded, 1 newly installed, 0 to remove and 11 not upgraded.
Need to get 23.8 MB of archives.
After this operation, 102 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Also, you can undo the effect via:

$ sudo apt-mark unhold snapd
Gea-Suan Lin
  • 406
  • 4
  • 7