无法安装 snap 包管理器

无法安装 snap 包管理器

前段时间我卸载了 snap,但可能把事情搞砸了,现在我无法重新安装它。当我尝试运行sudo apt install snapd此错误时,出现:

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

我的系统规格:

新取回

我应该怎么办?

我试过:

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

没有用。

cat /etc/apt/sources.list显示如下内容:

# 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显示如下:

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/显示如下:

nosnap.pref

cat nosnap.pref显示如下:

# 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

先感谢您。

答案1

/etc/apt/preferences.d/nosnap.pref似乎是一个APT 首选项控制文件有指令告诉 APT不是安装包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

因此您会看到以下错误消息:

E: Package 'snapd' has no installation candidate

这些 APT 首选项控制文件需要/etc/apt/preferences.d/遵循特定的命名约定,要求文件扩展名(如果使用) 的形式,.pref以便 APT 能够解析和处理它们。

因此,您可以通过将文件扩展名更改为.pref.disabled例如来禁用它们:

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

APT 可能会打印一条通知,指出它已忽略目录中的文件,/etc/apt/preferences.d/因为该文件的文件扩展名无效。

当然,将该文件移出目录/etc/apt/preferences.d/或删除它也是其他可行的替代方法,只需减去 APT 打印通知即可。

处理完该文件后,你应该能够snapd在更新 APT 的缓存存储库列表后进行安装(虽然这本身并不是必须的,但仍然是一种很好的做法

答案2

发生上述错误的原因是 APT 包管理器阻止了 snap 包的安装。

要启用 snap 支持,我们有两个选择:

选项 1:通过运行以下命令删除目录 /etc/apt/preferences.d 中的 nosnap.pref 文件:

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

选项 2:注释同一个文件中的三行代码。

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

现在,安装 snapd:

sudo apt install snapd

然后,您可以安装任何 snap 应用程序:

sudo snap install <app-name>

相关内容