Can't install snap the package manager

Some time ago I uninstalled snap, and probably messed things up cause now I can’t install it back. When I try to run sudo apt install snapd this error appears:

Package snapd is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'snapd' has no installation candidate

My system specs:

neofetch

What should I do?

Ps. I tried:

sudo apt-get purge snapd
sudo apt-get install snapd

didn’t work.

cat /etc/apt/sources.list displays this:

# deb cdrom:[Ubuntu 20.04.4 LTS _Focal Fossa_ - Release amd64 (20220223)]/ focal main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://archive.ubuntu.com/ubuntu jammy main restricted
# deb-src http://it.archive.ubuntu.com/ubuntu/ focal main restricted

## Major bug fix updates produced after the final release of the
## distribution.
# deb-src http://it.archive.ubuntu.com/ubuntu/ focal-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://archive.ubuntu.com/ubuntu jammy universe
# deb-src http://it.archive.ubuntu.com/ubuntu/ focal universe
# deb-src http://it.archive.ubuntu.com/ubuntu/ focal-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 
## team, and may not be under a free licence. Please satisfy yourself as to 
## your rights to use the software. Also, please note that software in 
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://archive.ubuntu.com/ubuntu jammy multiverse
# deb-src http://it.archive.ubuntu.com/ubuntu/ focal multiverse
# deb-src http://it.archive.ubuntu.com/ubuntu/ focal-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb-src http://it.archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse


deb http://archive.ubuntu.com/ubuntu jammy-security main restricted
# deb-src http://security.ubuntu.com/ubuntu focal-security main restricted
deb http://archive.ubuntu.com/ubuntu jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu focal-security universe
deb http://archive.ubuntu.com/ubuntu jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu focal-security multiverse

# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.
deb http://security.ubuntu.com/ubuntu/ jammy-security universe restricted main multiverse

sudo apt update && sudo apt -f install && sudo apt full-upgrade displayed this:

Hit:1 https://cli.github.com/packages stable InRelease
Hit:2 http://repository.spotify.com stable InRelease                           
Hit:3 http://archive.ubuntu.com/ubuntu jammy InRelease                         
Hit:4 https://download.docker.com/linux/ubuntu jammy InRelease                 
Hit:5 http://archive.ubuntu.com/ubuntu jammy-security InRelease                
Hit:6 http://security.ubuntu.com/ubuntu jammy-security InRelease               
Hit:7 http://packages.microsoft.com/repos/code stable InRelease                
Hit:8 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease   
Hit:9 https://dl.google.com/linux/chrome/deb stable InRelease                  
Hit:10 https://packages.redis.io/deb jammy InRelease                           
Hit:11 https://ppa.launchpadcontent.net/obsproject/obs-studio/ubuntu jammy InRelease
Hit:12 https://ppa.launchpadcontent.net/pipewire-debian/pipewire-upstream/ubuntu jammy InRelease
Hit:13 https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt/jammy pgadmin4 InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

ls /etc/apt/preferences.d/ displayed this:

nosnap.pref

cat nosnap.pref displayed this:

# To prevent repository packages from triggering the installation of snap,
# this file forbids snapd from being installed by APT.

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

Thank you in advance.

Asked By: Nedo

||

/etc/apt/preferences.d/nosnap.pref appears to be an APT preferences control file that has instructions telling APT to not install the package snapd:

# To prevent repository packages from triggering the installation of snap,
# this file forbids snapd from being installed by APT.

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

Hence the error message you see:

E: Package 'snapd' has no installation candidate

These APT preferences control files under /etc/apt/preferences.d/ need to follow a certain naming convention that requires the file extension(if one is used) to be in the form of .pref in order for APT to parse and process them.

Therefore, you can disable them by changing the file extension to e.g. .pref.disabled like so:

sudo mv /etc/apt/preferences.d/nosnap.pref /etc/apt/preferences.d/nosnap.pref.disabled

APT might print a notice that it has ignored a file in the directory /etc/apt/preferences.d/ because it has an invalid filename extension.

Of course moving that file outside the directory /etc/apt/preferences.d/ or deleting it are other alternatives that would work too minus the APT printed notice.

After dealing with that file, you should be able to install snapd after updating APT’s cached repositories lists(although not a must after that action per-se but good practice nonetheless)

Answered By: Raffa

The above error is happening because APT Package Manager blocks the installation of snap packages.

To enable snap support, we have two options:

Option 1: Delete the nosnap.pref file in the directory /etc/apt/preferences.d by running the command:

sudo rm /etc/apt/preferences.d/nosnap.pref

Option 2: Comment the three lines of code in the same file.

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

Now, install snapd:

sudo apt install snapd

And then, you can install any snap apps:

sudo snap install <app-name>
Answered By: Heisenbug