Ubuntu 22.04 禁用(彻底移除)Snap
前言
Snaps 是 Ubuntu 的母公司 Canonical 于 2016 年 4 月发布 Ubuntu 16.04 LTS(Long Term Support,长期支持版)时引入的一种容器化的软件包格式。自 Ubuntu 16.04 LTS 起,Ubuntu 操作系统可以同时支持 Snap 及 Debian 这两种格式的安装包。
Snap 虽然有一定的优点(请自行搜索),但是不足之处更多。Snap 软件包体积庞大,snapd 进程会导致系统重启等待,并且可能导致卡顿,禁用为佳。
特别是服务器版用不上这种软件包,默认是安装的,必须彻底删除。
Ubuntu 22.04 桌面版中两个关键的程序:软件商店和 Firefox 使用了 Snap 软件包,卡顿明显。
禁用服务无效示例:
1
2
3
4
5
6
#sudo systemctl disable --now snapd
#sudo systemctl disable --now snapd.socket
#sudo systemctl disable snapd
但是重启后,snapd 仍然运行
# 验证状态
systemctl status snapd
删除Snap 的方法
已经确认 snapd 是无法禁用的,只能强制删除。以下操作无需停止 snapd 服务。
①删掉所有的已经安装的Snap软件。
snap list
用于查看已经安装的 Snap 软件,通过脚本全部删除:
1
2
3
for p in $(snap list | awk '{print $1}'); do
sudo snap remove $p
done
一般需要执行两次(桌面版三次),提示如下则正确执行:
1
2
3
snap "Name" is not installed
core20 removed
snapd removed
再次执行,提示如下,表明已经删除干净:
1
No snaps are installed yet. Try 'snap install hello-world'.
②删除 Snap 的Core文件。
1
2
3
4
5
6
7
sudo systemctl stop snapd
sudo systemctl disable --now snapd.socket
for m in /snap/core/*; do
sudo umount $m
done
③删除 Snap 的管理工具。
1
sudo apt autoremove --purge snapd
④删除 Snap 的目录。
1
2
3
4
5
rm -rf ~/snap
sudo rm -rf /snap
sudo rm -rf /var/snap
sudo rm -rf /var/lib/snapd
sudo rm -rf /var/cache/snapd
⑤配置 APT 参数:禁止 apt 安装 snapd。
正确配置(参看 apt_preferences):
1
2
3
4
5
sudo sh -c "cat > /etc/apt/preferences.d/no-snapd.pref" << EOL
Package: snapd
Pin: release a=*
Pin-Priority: -10
EOL
1
2
3
4
5
a -> Archive
c -> Component
o -> Origin
l -> Label
n -> Architecture
验证效果:可以查询到该包,但是无法安装。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# sysin @ u22 in ~ [13:59:22]
$ apt list snapd
Listing... Done
snapd/jammy-updates 2.56.2+22.04ubuntu1 amd64
N: There is 1 additional version. Please use the '-a' switch to see it
# sysin @ u22 in ~ [13:59:37]
$ sudo apt install snapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
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
恢复Snap的方法
只需要删除配置文件,即可重新使用 Snap 软件包。
1
2
3
sudo rm /etc/apt/preferences.d/no-snap.pref
sudo apt update
sudo snap install snap-store
本文由作者按照
CC BY 4.0
进行授权