如何卸载 snap?

如何卸载 snap?

我已经使用 Ubuntu 12 年了,snapUbuntu 的最新版本实在是太糟糕了。它带来了很多问题。升级后,Chromium 无法启动,原因是出现以下错误:

chromium_chromium.desktop[122932]: snap-confine has elevated permissions and is not confined but should be. Refusing to continue to avoid permission escalation attacks: Operation not permitted

如果软件包在新版本中更改了配置,则它有责任使其正常工作。现在,我必须在每次启动后重新配置它,方法是

sudo apparmor_parser -r /etc/apparmor.d/*snap-confine*

我如何才能完全卸载 snap 并通过常规方式重新安装其软件包apt

我没有很多由 处理的包裹snap

snap list
Name               Version             Rev   Tracking         Publisher   Notes
chromium           85.0.4183.121       1328  latest/stable    canonical✓  -
core18             20200724            1885  latest/stable    canonical✓  base
gnome-3-34-1804    0+git.3556cb3       60    latest/stable    canonical✓  -
gtk-common-themes  0.1-36-gc75f853     1506  latest/stable    canonical✓  -
snap-store         3.36.0-80-g208fd61  467   latest/stable/…  canonical✓  -
snapd              2.46.1              9279  latest/stable    canonical✓  snapd

我的问题是如何安全地删除snap。从中snap list,我看到gnome取决于snap

答案1

在 Ubuntu 20.04 LTS 中(但它也适用于以下版本,直到 23.10,即当前版本),我snapd按照以下步骤删除了:

# stop snapd services
sudo systemctl stop snapd && sudo systemctl disable snapd

# Workaround for https://bugs.launchpad.net/ubuntu/+source/snapd/+bug/1998710
# This command is needed starting from Ubuntu 22.10
# Without it an error is returned when running the snapd purge command
# In that case you need to reinstall snapd to cleanly remove it in a second attempt
sudo snap remove firefox

# purge snapd
sudo apt purge snapd

# remove no longer needed folders
rm -rf ~/snap
sudo rm -rf /snap /var/snap /var/lib/snapd /var/cache/snapd /usr/lib/snapd /root/snap

然后,为了避免其他应用程序重新安装它(这是一个即使通过安装chromium-browser也会恢复的应用程序的示例),您可以通过以下命令创建一个文件:snapdaptno-snap.pref

sudo -H gedit /etc/apt/preferences.d/no-snap.pref

然后复制下面的内容进去:

# To install snapd, specify its version with 'apt install snapd=VERSION'
# where VERSION is the version of the snapd package you want to install.
Package: snapd
Pin: release a=*
Pin-Priority: -10

完成这些步骤后,Ubuntu 系统中两个最关键的应用程序 Software 和 Firefox 将被删除。在将来的 Ubuntu 24.10 中,通用 Unix 打印系统 (CUPS) 也将成为 snap 包。在运行这些命令之前,请先问问自己是否真的要删除 snapd,就像我一样。

考虑到有多种方式可以将 Firefox 安装为 deb,如果您将其用作默认浏览器,请确保备份书签和其他 Firefox 设置。

答案2

完全归功于 Don Prince 提供的全面有效的解决方案此链接

我建议你单独运行这些命令。有些命令你不需要,而有些命令你可能需要一两行额外的命令。

运行注释中列出的探索性信息命令来确定安装中的具体情况。

还安装了 Deb 打包的最后一个已知 Chromium 并将其固定,以防止 snapd 将来再次接管。太棒了!谢谢 Don!

#!/bin/bash

# probably best to manually type this commands individually checking for problems
 
# snap list | grep -v "^Name" | awk {'print "sudo snap remove " $1'}
 
sudo snap remove snap-store
sudo snap remove gtk-common-themes
sudo snap remove gnome-3-28-1804
sudo snap remove gnome-3-34-1804
sudo snap remove core18
sudo snap remove snapd
snap list # expect: No snaps are installed yet. Try 'snap install hello-world'.
 
sudo umount /run/snap/ns
 
sudo systemctl disable snapd.service
sudo systemctl disable snapd.socket
sudo systemctl disable snapd.seeded.service
sudo systemctl disable snapd.autoimport.service
sudo systemctl disable snapd.apparmor.service
 
sudo rm -rf /etc/apparmor.d/usr.lib.snapd.snap-confine.real
 
sudo systemctl start apparmor.service
 
# df | grep snap | awk {'print "sudo umount " $6'}
sudo umount /snap/chromium/1424
sudo umount /snap/gtk-common-themes/1514
sudo umount /snap/gnome-3-28-1804/145
sudo umount /snap/core18/1944
sudo umount /snap/snapd/10492
sudo umount /var/snap
 
sudo apt purge snapd
 
# find / -type d -iname '*snap*'
# (I left the kernel entries well alone)
rm -rf ~/snap
sudo rm -rf /snap /var/snap /var/lib/snapd /var/cache/snapd /usr/lib/snapd
sudo rm -rf /root/snap /root/snap/snap-store /usr/share/doc/libsnapd-glib1 /usr/share/doc/gir1.2-snapd-1
 
cat <<EOF | sudo tee /etc/apt/preferences.d/snapd
Package: snapd
Pin: origin *
Pin-Priority: -1
EOF
 
cat <<EOF | sudo tee /etc/apt/preferences.d/pin-xalt7x-chromium-deb-vaapi
Package: *
Pin: release o=LP-PPA-xalt7x-chromium-deb-vaapi
Pin-Priority: 1337
EOF
 
sudo add-apt-repository ppa:xalt7x/chromium-deb-vaapi
 
sudo apt update
sudo apt-get install chromium-browser

答案3

我同意你关于快照的看法。

我通过以下步骤彻底删除了系统中的快照:

sudo apt-get purge snapd
rm -rf ~/snap                                      
sudo rm -rf /snap                                  
sudo rm -rf /var/snap                              
sudo rm -rf /var/lib/snapd 

现在系统运行良好,尽管我不得不用 APT 或 .deb 文件版本(如果有)替换 snap 程序。不幸的是,我丢失了一个我需要的应用程序,但这是我必须付出的代价,但我获得了一些磁盘空间,并且我的启动时间也短了一些。

gnome 仍安装并像以前一样正常运行

终端中显示的 gnome shell 版本

相关内容