最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Linux如何清理无用包
时间:2026-08-21 20:23:51 编辑:袖梨 来源:一聚教程网
在 Linux 中清理无用包(不再需要的依赖、缓存、旧内核等),不同发行版命令不同。下面按常见发行版给你一份实用速查表。

一、Debian / Ubuntu / Linux Mint
删除不再需要的依赖包
sudo apt autoremove会删除“曾经作为依赖安装、但现在没有任何软件使用”的包。
清理下载的安装包缓存
sudo apt clean或只删除旧版本:
sudo apt autoclean删除旧内核(谨慎)
查看当前内核:
uname -r列出已安装内核:
dpkg --list | grep linux-image删除旧内核(不要删当前使用的):
sudo apt remove linux-image-旧版本-generic推荐工具(安全)
sudo apt install byobusudo purge-old-kernels
二、RHEL / CentOS / Rocky / AlmaLinux
删除无用依赖
sudo yum autoremove或(CentOS 8+ / Rocky / Alma):
sudo dnf autoremove清理缓存
sudo yum clean all或:
sudo dnf clean all删除旧内核
uname -rrpm -qa kernel
保留当前内核,删除旧版本:
sudo yum remove kernel-旧版本三、Arch Linux / Manjaro
删除孤立包
sudo pacman -Rns $(pacman -Qdtq)清理包缓存
sudo pacman -Sc或彻底清理(谨慎):
sudo pacman -Scc清理旧内核
Arch 通常只保留当前内核,手动删除旧版本:
sudo pacman -R linux-lts四、通用清理(所有发行版)
清理用户缓存
rm -rf ~/.cache/*查找大文件(手动清理)
du -h --max-depth=1 /var | sort -hr日志清理
sudo journalctl --vacuum-time=7d五、一键清理(推荐新手)
Ubuntu / Debian
sudo apt update && sudo apt autoremove -y && sudo apt autocleanCentOS / Rocky / Alma
sudo dnf autoremove -y && sudo dnf clean all六、注意事项
- 不要删除 当前正在使用的内核
clean不会影响系统运行,但purge会彻底删除配置- 生产服务器建议先
dry-run或备份
如果你愿意,可以告诉我:
- 你的 Linux 发行版 + 版本
- 是 桌面还是服务器
- 是否担心误删内核
我可以给你最安全的一套命令。
相关文章
- 小米路由器cr6608怎么设置上网(小米路由器cr6608上网设置方法) 08-21
- Ubuntu别名如何添加 08-21
- 个人创业者如何选适配 AI IP 赛道?五层自测精准锁定方向 08-21
- 重塑物理世界的“神经系统”,澜存科技三个月内连融两轮 08-21
- 非匿名指令什么英雄厉害-非匿名指令哪个英雄好 08-21
- 涂鸦智能与万魔科技达成深度合作 联手打造更易用的智能音频产品 08-21