![使用 apt/aptitude,如何删除发行版升级后所有无源的旧软件包?](https://linux22.com/image/206465/%E4%BD%BF%E7%94%A8%20apt%2Faptitude%EF%BC%8C%E5%A6%82%E4%BD%95%E5%88%A0%E9%99%A4%E5%8F%91%E8%A1%8C%E7%89%88%E5%8D%87%E7%BA%A7%E5%90%8E%E6%89%80%E6%9C%89%E6%97%A0%E6%BA%90%E7%9A%84%E6%97%A7%E8%BD%AF%E4%BB%B6%E5%8C%85%EF%BC%9F.png)
几周前我将 Linux 从 Pop_OS 21.10 升级到 22.04。
发行版升级大概用新版本替换了一些旧源,因此,Pop_OS 21.10 或更早版本的许多现有软件包现在都是无源的:
$ sudo aptitude update
W: Package containerd.io had been marked to reinstall, but the file for the current installed version 1.4.13-1 is not available
W: Package scala-cli had been marked to reinstall, but the file for the current installed version 0.1.2 is not available
W: Package libfam0 had been marked to reinstall, but the file for the current installed version 2.7.0-17.3build2 is not available
W: Package ksysguardd had been marked to reinstall, but the file for the current installed version 4:5.22.0-0ubuntu1 is not available
W: Package gnome-getting-started-docs-de had been marked to reinstall, but the file for the current installed version 3.36.2-0ubuntu0.1 is not available
W: Package gnome-getting-started-docs-es had been marked to reinstall, but the file for the current installed version 3.36.2-0ubuntu0.1 is not available
W: Package gnome-getting-started-docs-fr had been marked to reinstall, but the file for the current installed version 3.36.2-0ubuntu0.1 is not available
W: Package gnome-getting-started-docs-it had been marked to reinstall, but the file for the current installed version 3.36.2-0ubuntu0.1 is not available
W: Package gnome-getting-started-docs-ja had been marked to reinstall, but the file for the current installed version 3.36.2-0ubuntu0.1 is not available
W: Package gnome-getting-started-docs-pt had been marked to reinstall, but the file for the current installed version 3.36.2-0ubuntu0.1 is not available
W: Package gnome-getting-started-docs-ru had been marked to reinstall, but the file for the current installed version 3.36.2-0ubuntu0.1 is not available
W: Package docker-ce-cli had been marked to reinstall, but the file for the current installed version 5:20.10.12~3-0~ubuntu-focal is not available
W: Package wolframscript had been marked to reinstall, but the file for the current installed version 1.2.0+2019040701 is not available
W: Package libvala-0.48-0 had been marked to reinstall, but the file for the current installed version 0.48.6-0ubuntu1 is not available
W: Package linux-headers-5.11.0-7614-generic had been marked to reinstall, but the file for the current installed version 5.11.0-7614.15~1622578982~20.04~383c0a9 is not available
W: Package llvm-10-dev had been marked to reinstall, but the file for the current installed version 1:10.0.0-4ubuntu1 is not available
W: Package linux-headers-5.15.8-76051508-generic had been marked to reinstall, but the file for the current installed version 5.15.8-76051508.202112141040~1639505278~20.04~0ede46a is not available
W: Package ksysguard had been marked to reinstall, but the file for the current installed version 4:5.22.0-0ubuntu1 is not available
W: Package gcc-8 had been marked to reinstall, but the file for the current installed version 8.5.0-0ubuntu4 is not available
W: Package linux-modules-5.16.19-76051619-generic had been marked to reinstall, but the file for the current installed version 5.16.19-76051619.202204081339~1649696161~22.04~091f44b is not available
W: Package minikube had been marked to reinstall, but the file for the current installed version 1.25.2-0 is not available
W: Package oem-sutton.newell-meta had been marked to reinstall, but the file for the current installed version 4.0newell5 is not available
W: Package linux-modules-5.15.8-76051508-generic had been marked to reinstall, but the file for the current installed version 5.15.8-76051508.202112141040~1639505278~20.04~0ede46a is not available
W: Package libllvm10 had been marked to reinstall, but the file for the current installed version 1:10.0.0-4ubuntu1 is not available
W: Package gcc-8-base had been marked to reinstall, but the file for the current installed version 8.5.0-0ubuntu4 is not available
W: Package libsepol1 had been marked to reinstall, but the file for the current installed version 3.1-1ubuntu2.1 is not available
我需要将它们全部删除(否则它们会浪费磁盘空间并可能导致奇怪的冲突),我该怎么做?可以使用任何基于 Ubuntu/debian 的包管理器提供解决方案。
答案1
您可以通过将该输出保存到文件(例如,使用重定向或只需鼠标复制和粘贴,因为它是一个相当小的列表)并通过运行它来轻松提取包名称awk '{print $3}'
,因为包名称位于每行的第三个字段中。然后,您可以通过apt-get remove
orapt-get purge
命令使用这些包名称。
aptitude search
您还可以使用- 例如获取“过时”软件包的列表aptitude -F %p search '?obsolete'
。这可能会产生比“标记为重新安装”的包名称更大的包名称列表......但是如果不知道您的sources.list配置和您正在使用的任何存储库的当前状态,就不可能确定。
但是,自动删除大量软件包最终可能会删除比您想象的要多得多的软件包,因为其他软件包可能依赖于您要删除的某些软件包。库包(例如libfam0
、libvala-0.48-0
和libsepol1
)特别有可能导致这种情况。删除containerd.io
可能会导致 docker 或类似的容器管理工具被卸载。
我强烈建议不要自动删除这些软件包。
有选择地卸载精心挑选的软件包如果以及当它们被证明是一个问题时应该没问题,但(除了少数例外)它们消耗的磁盘空间量不值得冒无故删除它们的风险。
旧的内核头相当大(~50MB)并且通常可以安全地删除 - 它们实际上只有在您需要为已安装的内核编译内核模块(例如使用 dkms)时才有用。而且您可能不需要这么多语言的 gnome 入门文档。
您可能还会发现您正在删除经常使用但不再位于发行版中的软件包,因为软件包维护者不再有时间维护它。我知道我的 Debian 机器上有几个类似的东西,特别是那些自 20 世纪 90 年代以来不断升级的机器。例如,我讨厌自动删除我的 roxterm 软件包 - 它已经过时了很多年,甚至被作者放弃了,但我仍然使用它,因为它比任何其他基于 libvte 的终端模拟器要少得多...... .而且,即使它是废弃软件,它仍然工作得很好。
顺便说一句,值得记住的是,W:
每行的前缀表示一个警告,不是错误条件。它指出了一些值得注意的事情,但不一定是需要解决的实际问题。