什么是 `sudo apt-get clean`?

当我收到软件更新的消息并点击安装时,我收到一个"空间不足"的消息,告诉我清空垃圾桶并使用sudo apt-get clean命令删除临时文件。我已经清空了垃圾桶,但仍然收到相同的消息,不知道应该删除哪些临时文件,也不知道sudo apt-get clean是什么。

我不清楚"sudo apt-get clean",但是你可以尝试使用"sudo apt-get autoremove",它也可以帮助释放一些空间。 - Nori-chan
对话是否类似于这个的告知'/boot'没有足够的空间? - jarno
请标注您受到相关错误的影响。您还可以在其评论中找到有用的信息。 - jarno
你正在使用哪个版本的Ubuntu?(在终端中输入“lsb_release -r”的输出) - jarno
运行sudo apt-get clean和清空垃圾桶可能不会有帮助,如果你的系统有一个独立的/boot分区。 - jarno
鉴于问题实际上并不是“sudo apt-get clean是什么”,或许可以为未来的读者重新命名此问题,以免他们点击后感到失望? - user12753
2个回答

sudo apt-get clean 清空本地仓库中检索到的软件包文件。它会从 /var/cache/apt/archives//var/cache/apt/archives/partial/ 中删除除锁定文件之外的所有内容。

来源:man apt-get

另一种使用命令 sudo apt-get clean 查看其执行情况的可能性是通过使用 -s 选项进行模拟执行。

mook@MookPC:~$ apt-get -s clean
注意:这只是一个模拟!
      apt-get 需要 root 权限进行真正的执行。
      还请记住锁定已禁用,
      因此不要依赖于与真实当前情况的相关性!
删除 /var/cache/apt/archives/* /var/cache/apt/archives/partial/*
删除 /var/lib/apt/lists/partial/*
删除 /var/cache/apt/pkgcache.bin /var/cache/apt/srcpkgcache.bin
mook@MookPC:~$ sudo apt-get -s clean
[sudo] 输入 mook 的密码:
删除 /var/cache/apt/archives/* /var/cache/apt/archives/partial/*
删除 /var/lib/apt/lists/partial/*
删除 /var/cache/apt/pkgcache.bin /var/cache/apt/srcpkgcache.bin
感谢 @jarno 的建议。

2您可以模拟运行“apt-get -s clean”命令,以查看它的效果。作为普通用户运行该命令会删除/var/cache/apt/路径下除上述所提及文件之外的一些文件。 - jarno
1在Ubuntu中,所谓的“本地软件包仓库”是什么? - pkaramol

如果您收到“空间不足”的消息,并且命令sudo apt-get clean无效,请尝试以下操作:
打开终端, 按下Ctrl+Alt+T
运行它:
sudo -i   # (Allows you to execute commands with the privileges of the superuser.)       

KERNELCUR=$(uname -r | sed 's/-*[a-z]//g' | sed 's/-386//g')
PKGLINUX="linux-(image|headers|ubuntu-modules|restricted-modules)"
METAPKGLINUX="linux-(image|headers|restricted-modules)-(generic|i386|server|common|rt|xen)"
KERNELSOLD=$(dpkg -l | awk '{print $2}' | grep -E "$PKGLINUX" | grep -vE "$METAPKGLINUX" | grep -v "$KERNELCUR")

apt-get purge "$KERNELSOLD"   # (Remove old kernels.)

CONFOLD=$(dpkg -l | grep '^rc' | awk '{print $2}')  

apt-get purge "$CONFOLD"   # (Removes configuration files from deb packages that have been uninstalled.)
apt-get autoremove   # (Deletes orphaned packages, or dependencies that remain installed after you have installed an application and then deleted it.)
apt-get clean   # (Removes all packets from the cache.)
rm -rf /home/*/.local/share/Trash/*/** &> /dev/null   # (Empty the trash from all users.)
rm -rf /root/.local/share/Trash/*/** &> /dev/null   # (Empty the trash from root.)

如果依赖的内核不是当前版本,系统会清除元内核"linux-image-generic",从而阻止显示进一步的内核更新。 - jarno
@Zanna:您的请求已经收到。 - kyodake
1...或者,只需执行 apt autoremove && apt clean。 - bviktor