Apt installer

How can you ensure that when using the "sudo apt install [name of app]" command only .deb packages are installed, even if package management for flatpaks and snaps is enabled on the device?

Previously I always thought this command would only install .deb packages, but this seems to have changed and will soon become more relevant with newer Ubuntu versions.
The reason I ask is that in the advice here on the forum, many newbies have no experience with synaptic and it is not pre-installed and also flatpaks and snaps are available by default.

Is it possible to modify the command or change something in the configuration settings so that no package format other than .deb is installed?

So as far as I'm aware I've never seen a Flatpak get installed via this command, unless something has changed that I haven't noticed. There is the issue of Snap, however. The way you would have to go about making sure that doesn't happen involves purging snap first:

sudo apt remove --purge snapd

Then you could do one of two ways. You could do the way Linux Mint handles it, which is a file as follows:

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

Another way I saw that you could do is force a hold on the snap package, such as sudo apt-mark hold snapd. That would show an error if you tried to install with apt a package that would try to install via Snap. Both options require snap to be purged in the first place.

Again, I haven't seen Flatpak get installed via apt this way, but maybe somethings changed that I haven't seen.

2 Likes

I only read that snaps are installed this way. I searched for a solution so that it doesn't happen when I advice another user who has enabled snaps (without neccessary of completely removing snaps before).

1 Like

It is not, because this is not a command or configuration issue.

What Canonical does is use Stub pacakges.
So if you install a package using the apt command, that leads to an actual .deb package that Canonical has configured to then redirect to install snapd and the package as a Snap.
This is done by the stub and not by APT.

This is part of why what Canonical is doing (and has been doing) is so devious and forceful.

7 Likes

I just thought I'd gotten to understanding installing software using the terminal.

Another spanner. Oh dear :eyes:

To be fair, this particular dirty trick can also happen when using a graphical tool like the software store, because as Aravisian said, it's not the command doing it--it's installing a .deb like it should, but that .deb doesn't install the program it says it does--it installs a snap installer, which then installs the program.

What about setting a package's priority to -1 in /etc/apt/preferences? If I understand correctly (and I may not), it should be possible to block installation of snapd with this addition to /etc/apt/preferences:

Package: snapd
Pin: release *
Pin-Priority: -1

This won't fix the fact that the .deb contains a stub installer, but the install should fail trying to install snapd. At the very least, the user isn't suckered into thinking they have a deb installed when it's actually a snap, and doesn't have to then remove the snap and re-remove snapd.

It's like an emergency shutoff valve. You may not get the water (program) you wanted, but it prevented a problem from occurring.

1 Like

That may work but what got me was:

If Snap is enabled, then SnapD must already be installed.
My interpretation of this question was that:
A user can still install Snap Packages by choice and by using snap install, but apt not be redirected to install a package via Snap.

Otherwise, sudo apt remove snapd gnome-software-plugin-snap would remain the clear answer.

This means that you can only prevent the installation of snaps by deactivating snapd and removing the plugin for snaps from gnome-software, but additionally you have to create mark-hold snapd or the configuration file like in Linux Mint? Wow!!! Quite intrusive and sneaky these snaps :slightly_frowning_face:

Ah, right. It's late (or early). That was predicated as you say.

Another option would be to not rely on Canonical's repositories. This is one reason why moving the base to Debian might be a good decision.

1 Like

Thanks for all the suggestions!
@Locklear93 This suggestion sounds good too, but it also completely disables the installation of snaps. Since some users may not want that, I was wondering if it could be set for just one command when installing a specific program.
e.g. I read that "sudo apt install telegram-desktop" could install the snap version in newer ubuntu versions, so I wanted to make sure that only .deb package is installed and if it doesn't exists, the installation would fail.

You can use the snap command as per usual, just like there's one for flatpak.

Unfortunately, the method I suggested disables one package. That command doesn't know anything about snaps or what's actually going to be installed by a given .deb. It disables snap by preventing snap's package from being installed. If you had a list of every .deb that installed a snap, you could add all of them--but then you wouldn't be able to install those programs via APT at all, and would HAVE to use a snap or flatpak--and also here's no way I know to get such a list.

Ah, now it is clearer for me. I thought this entry in the mentioned file is valid for all snaps.
Unfortunately, there is probably no such list. A change in this file is therefore not suitable as a precaution if you do not yet know what exactly will be installed.
In the case of programs that are secretly installed as a snap via apt in this way, there is often no .deb package in the repo, but sometimes only the pure .deb file or a tar.gz, which you then have to install.

But when there are two possibilities to install a package and the command is the same (I saw this problem with firefox), then it could help, or?
E.g. the repo/ ppa of a program is added.
The program can be installed with
sudo apt install ...
Ubuntu also offers this program but only as snap not as .deb and the command to install is the same
sudo apt install ... (without snap in command, but it leads to snap)
Then the system would choose the ubuntu one by default.

Flatpaks should be installed that Way. But Snaps can be ... this is an Ubuntu Thing. Firefox is the best example for this. When you would make a sudo apt install firefox on Ubuntu without Changes, You get the Snap Firefox. If I remember right, it will shown to You that the Snap Package will be installed.

When You now add the Mozilla Repo to get Firefox as .deb Package directly from Mozilla, on of the Steps to add it is creating a File for Preference - similar this this what @applecheeks37 and @Locklear93 already have shown. But in this Case it has a higher Priority than the Snap Packages it get installed - and that is the Reason why You get the Friefox Package from Mozilla.

Wouldn't You have this File, You would still get the Snap Firefox by default - even with added Mozilla Repo.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.