Ubuntu卸载snap

2024-05-08 22:04
文章标签 ubuntu 卸载 snap

本文主要是介绍Ubuntu卸载snap,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

Ubuntu卸载snap

文章目录

  • Ubuntu卸载snap
  • 1.打开终端,输入`snap list`,查看已安装的软件
  • 2.停止snapd服务
  • 3.依次移除snap安装的软件
  • 4.完全清除 snapd
  • 5.删除缓存目录(如有)
  • 6.防止apt update自动安装snap
  • 7.一键ubuntu卸载snap脚本

最近由于复现实验新装了Ubuntu20.04,发现后台中snapd进程占用高。snap是Canonical公司推出的一款软件管理工具,在20.04以及之后版本Ubuntu中都有预装,但因其难用,资源占用高被广为诟病,特搜索整理资料将其卸载。

1.打开终端,输入snap list,查看已安装的软件

root@ubuntu2204:~# snap list
Name    Version        Rev    Tracking       Publisher   Notes
core20  20230622       1974   latest/stable  canonical✓  base
lxd     5.0.2-838e1b2  24322  5.0/stable/…   canonical✓  -
snapd   2.59.5         19457  latest/stable  canonical✓  snapd

2.停止snapd服务

root@ubuntu2204:~# systemctl disable snapd.service && systemctl disable snapd.socket && systemctl disable snapd.seeded.service

3.依次移除snap安装的软件

运行 sudo snap remove --purge lxd 等命令依次删除前面列表中的各个软件,需要注意的是在上述列表notes列表明是base的表示是其他软件的依赖项,需要放在最后面删除。比如上图中的core20等等

root@ubuntu2204:~# vi remove_snap_package.sh
#!/bin/bash
sum=$(snap list | awk 'NR>=2{print $1}' | wc -l)
while [ $sum -ne 0 ];dofor p in $(snap list | awk 'NR>=2{print $1}') ;dosnap remove --purge $pdonesum=$(snap list | awk 'NR>=2{print $1}' | wc -l)
doneroot@ubuntu2204:~# bash remove_snap_package.sh
# 提示如下,表明已经删除干净:
No snaps are installed yet. Try 'snap install hello-world'.

4.完全清除 snapd

root@ubuntu2204:~# apt -y autoremove --purge snapd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:snapd* squashfs-tools* ubuntu-server-minimal*
0 upgraded, 0 newly installed, 3 to remove and 33 not upgraded.
After this operation, 103 MB disk space will be freed.
(Reading database ... 74127 files and directories currently installed.)
Removing ubuntu-server-minimal (1.481.1) ...
Removing snapd (2.58+22.04.1) ...
Warning: Stopping snapd.service, but it can still be activated by:snapd.socket
Removing squashfs-tools (1:4.5-3build1) ...
Processing triggers for dbus (1.12.20-2ubuntu4.1) ...
Processing triggers for man-db (2.10.2-1) ...
(Reading database ... 74018 files and directories currently installed.)
Purging configuration files for snapd (2.58+22.04.1) ...
rmdir: failed to remove '/etc/systemd/system/snapd.mounts.target.wants': No such file or directory
Discarding preserved snap namespaces
Final directory cleanup
Removing extra snap-confine apparmor rules
Removing snapd cache
Removing snapd state

5.删除缓存目录(如有)

root@ubuntu2204:~# rm -rf ~/snap && sudo rm -rf /snap && rm -rf /var/snap && rm -rf /var/lib/snapd && rm -rf /var/cache/snapd

6.防止apt update自动安装snap

即使使用以上命令移除了 Snap 软件包,但如果没有关闭 apt 触发器,sudo apt update命令会再一次将 Snap 安装回来。

要关闭它,需要在/etc/apt/preferences.d/目录下创建一个 apt 设置文件nosnap.pref来阻止 Snap 服务自动下载

运行命令vi /etc/apt/preferences.d/nosnap.pref,打开编辑器,输入以下内容并保存文件

root@ubuntu2004:~# cat > /etc/apt/preferences.d/no-snapd.pref << EOF
Package: snapd
Pin: release a=*
Pin-Priority: -10
EOF

文件保存后运行sudo apt update 即可。

root@ubuntu2204:~# apt update

7.一键ubuntu卸载snap脚本

Shell脚本源码地址:

Gitee:https://gitee.com/raymond9/shell
Github:https://github.com/raymond999999/shell

可以去上面的Gitee或Github代码仓库拉取脚本。

root@ubuntu2204:~# cat remove_snap.sh 
#!/bin/bash
#
#***************************************************************************************************
#Author:        Raymond
#QQ:            88563128
#Date:          2024-05-06
#FileName:      remove_snap.sh
#MIRROR:        raymond.blog.csdn.net
#Description:   remove_snap for Ubuntu 20.04/22.04
#Copyright (C): 2024 All rights reserved
#***************************************************************************************************
COLOR="echo -e \\033[01;31m"
END='\033[0m'ubuntu_remove_snap(){dpkg -s snapd &> /dev/null || { ${COLOR}"snap已卸载!"${END};exit; }systemctl disable snapd.service && systemctl disable snapd.socket && systemctl disable snapd.seeded.servicesum=$(snap list | awk 'NR>=2{print $1}' | wc -l)while [ $sum -ne 0 ];dofor p in $(snap list | awk 'NR>=2{print $1}'); dosnap remove --purge $pdonesum=$(snap list | awk 'NR>=2{print $1}' | wc -l)doneapt -y autoremove --purge snapdrm -rf ~/snap && sudo rm -rf /snap && rm -rf /var/snap && rm -rf /var/lib/snapd && rm -rf /var/cache/snapdcat > /etc/apt/preferences.d/no-snapd.pref << EOF
Package: snapd
Pin: release a=*
Pin-Priority: -10
EOFapt update
}main(){ubuntu_remove_snap
}

这篇关于Ubuntu卸载snap的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/971562

相关文章

Python UV安装、升级、卸载详细步骤记录

《PythonUV安装、升级、卸载详细步骤记录》:本文主要介绍PythonUV安装、升级、卸载的详细步骤,uv是Astral推出的下一代Python包与项目管理器,主打单一可执行文件、极致性能... 目录安装检查升级设置自动补全卸载UV 命令总结 官方文档详见:https://docs.astral.sh/

Ubuntu设置程序开机自启动的操作步骤

《Ubuntu设置程序开机自启动的操作步骤》在部署程序到边缘端时,我们总希望可以通电即启动我们写好的程序,本篇博客用以记录如何在ubuntu开机执行某条命令或者某个可执行程序,需要的朋友可以参考下... 目录1、概述2、图形界面设置3、设置为Systemd服务1、概述测试环境:Ubuntu22.04 带图

Ubuntu上手动安装Go环境并解决“可执行文件格式错误”问题

《Ubuntu上手动安装Go环境并解决“可执行文件格式错误”问题》:本文主要介绍Ubuntu上手动安装Go环境并解决“可执行文件格式错误”问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未... 目录一、前言二、系统架构检测三、卸载旧版 Go四、下载并安装正确版本五、配置环境变量六、验证安装七、常见

ubuntu如何部署Dify以及安装Docker? Dify安装部署指南

《ubuntu如何部署Dify以及安装Docker?Dify安装部署指南》Dify是一个开源的大模型应用开发平台,允许用户快速构建和部署基于大语言模型的应用,ubuntu如何部署Dify呢?详细请... Dify是个不错的开源LLM应用开发平台,提供从 Agent 构建到 AI workflow 编排、RA

ubuntu系统使用官方操作命令升级Dify指南

《ubuntu系统使用官方操作命令升级Dify指南》Dify支持自动化执行、日志记录和结果管理,适用于数据处理、模型训练和部署等场景,今天我们就来看看ubuntu系统中使用官方操作命令升级Dify的方... Dify 是一个基于 docker 的工作流管理工具,旨在简化机器学习和数据科学领域的多步骤工作流。

如何在Ubuntu上安装NVIDIA显卡驱动? Ubuntu安装英伟达显卡驱动教程

《如何在Ubuntu上安装NVIDIA显卡驱动?Ubuntu安装英伟达显卡驱动教程》Windows系统不同,Linux系统通常不会自动安装专有显卡驱动,今天我们就来看看Ubuntu系统安装英伟达显卡... 对于使用NVIDIA显卡的Ubuntu用户来说,正确安装显卡驱动是获得最佳图形性能的关键。与Windo

双系统电脑中把Ubuntu装进外接移动固态硬盘的全过程

《双系统电脑中把Ubuntu装进外接移动固态硬盘的全过程》:本文主要介绍如何在Windows11系统中使用VMware17创建虚拟机,并在虚拟机中安装Ubuntu22.04桌面版或Ubunt... 目录一、首先win11中安装vmware17二、磁盘分区三、保存四、使用虚拟机进行系统安装五、遇见的错误和解决

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

如何将Python彻底卸载的三种方法

《如何将Python彻底卸载的三种方法》通常我们在一些软件的使用上有碰壁,第一反应就是卸载重装,所以有小伙伴就问我Python怎么卸载才能彻底卸载干净,今天这篇文章,小编就来教大家如何彻底卸载Pyth... 目录软件卸载①方法:②方法:③方法:清理相关文件夹软件卸载①方法:首先,在安装python时,下

Ubuntu中远程连接Mysql数据库的详细图文教程

《Ubuntu中远程连接Mysql数据库的详细图文教程》Ubuntu是一个以桌面应用为主的Linux发行版操作系统,这篇文章主要为大家详细介绍了Ubuntu中远程连接Mysql数据库的详细图文教程,有... 目录1、版本2、检查有没有mysql2.1 查询是否安装了Mysql包2.2 查看Mysql版本2.