如何重现错误“包…需要重新安装,但我找不到它的存档”进行测试?

Ubuntu用户有时会遇到aptapt-get错误,forms如下:

 The package some-package needs to be reinstalled, but I can't find an archive for it. 

我想知道导致此错误的原因,以便我可以重现它并尝试找到修复它的安全方法,即使破坏的包很重要并且有很多依赖项。 APT源代码的 这一点可能会给出一些线索,但我不知道软件包如何获得导致错误的状态。

如何在我的(Ubuntu MATE 17.10)系统上测试产生此错误?

这是由最近的Ask Ubuntu问题引起的 ,我对Apt / Synaptic关于此错误的关闭问题的长期不安需要重新安装包但无法找到它的存档 ,其答案使用dpkg --force-all来删除违规的包裹。 匿名反馈表明这个解决方案对很多用户都有效,但我不相信使用--force-all不会导致以后出现问题,或者使用这种方法移除像APT这样的重要软件包是个好主意。

错误“Apt / Synaptic需要重新安装包但无法找到它的存档”有时是非特定的。

我看到此错误的最常见时间是将Ubuntu从一个版本升级到另一个版本。

注意 :Ubuntu正在从apt-get转换为apt,但我在这篇文章中使用了apt-get。 有关其他信息,请参阅man apt和https://www.debian.org/doc/manuals/debian-reference/ch02.en.html

导致此错误的最常见原因是用户安装了一个包,然后删除了.deb,通常使用sudo apt-get clean

http://manpages.ubuntu.com/manpages/zesty/man8/apt-get.8.html

清洁

  clean clears out the local repository of retrieved package files. It removes everything but the lock file from /var/cache/apt/archives/ and /var/cache/apt/archives/partial/ 

然后,在某些时候, dpkg --reconfigure被用户或升级调用,或者在某些时候用户尝试重新安装包,重新安装sudo apt-get --reinstall foo或一些变体。

如果apt无法在存储库中找到.deb,或者因为包被删除(很少见),存储库已从系统中删除,或者升级并且包不在新存储库中,您将收到错误“Apt / Synaptic需要重新安装包但无法找到它的存档“


但错误可能来自其他原因。

从dpkg手册页引用相关部分(有关详细信息,请参阅http://manpages.ubuntu.com/manpages/trusty/man1/dpkg.1.html )

有关包的信息dpkg维护有关可用包的一些可用信息。 信息分为三类:状态,选择状态和标志。 这些值主要用dselect更改。

包状态

  not-installed The package is not installed on your system. config-files Only the configuration files of the package exist on the system. half-installed The installation of the package has been started, but not completed for some reason. unpacked The package is unpacked, but not configured. half-configured The package is unpacked and configuration has been started, but not yet completed for some reason. triggers-awaited The package awaits trigger processing by another package. triggers-pending The package has been triggered. installed The package is unpacked and configured OK. 

行动

  -i, --install package-file... Install the package. If --recursive or -R option is specified, package-file must refer to a directory instead. Installation consists of the following steps: 1. Extract the control files of the new package. 2. If another version of the same package was installed before the new installation, execute prerm script of the old package. 3. Run preinst script, if provided by the package. 4. Unpack the new files, and at the same time back up the old files, so that if something goes wrong, they can be restored. 5. If another version of the same package was installed before the new installation, execute the postrm script of the old package. Note that this script is executed after the preinst script of the new package, because new files are written at the same time old files are removed. 6. Configure the package. See --configure for detailed information about how this is done. 

–configure package … | -a | –pending

  Configure a package which has been unpacked but not yet configured. If -a or --pending is given instead of package, all unpacked but unconfigured packages are configured. To reconfigure a package which has already been configured, try the dpkg-reconfigure(8) command instead. Configuring consists of the following steps: 1. Unpack the conffiles, and at the same time back up the old conffiles, so that they can be restored if something goes wrong. 2. Run postinst script, if provided by the package. /var/lib/dpkg/status Statuses of available packages. This file contains information about whether a package is marked for removing or not, whether it is installed or not, etc. See section INFORMATION ABOUT PACKAGES for more info. 

如果手册页是tl; dr – >作为安装的一部分,.deb / dpkg / apt运行安装前脚本和其他function。 如果这些安装/删除脚本由于各种原因而失败,则程序包将标记为“半安装”(或未安装/安装的某些状态)。 在那个不洁净的状态下,您有时也会看到错误“Apt / Synaptic需要重新安装包但无法找到它的存档”。 在此示例中,问题不是缺少存档,而是安装前/后安装脚本中的问题,无法通过重新运行它们来解决。 因此,错误有时是非特定的。


如何管理破损的包裹

  1. 首先尝试通过确保启用适当的ppa /存储库,例如Universe或需要任何存储库来首先修复依赖项。

    • 如何启用“Universe”存储库?

    • 什么是PPA以及如何使用它们?

    然后臭名昭着

     sudo apt-get install -f 

    如果需要帮助,请阅读所有输出和错误消息并在此处发布命令和输出。

  2. 尝试重新配置

     sudo dpkg --configure -a 

    这将运行配置脚本。 你可以指定一个包而不是-a,但是当你遇到问题时-a更有帮助。

    如果需要帮助,请阅读所有输出和错误消息并在此处发布命令和输出。

    尝试查看任何失败的脚本,如果可能,修复脚本中的错误/问题。

  3. 如有必要,请尝试强制删除有问题的包裹。 你必须非常小心,你可以强制删除关键包或更糟糕的关键包。 以下命令从礼貌到不太礼貌到彻头彻尾的力量。 按顺序尝试。

     sudo dpkg --remove $broken_package sudo dpkg --remove --force-remove-reinstreq $broken_package sudo dpkg --remove --force-all $broken_package 

    如果其中任何一个工作,运行sudo apt-get update && sudo apt-get upgrade ,你可能还需要运行sudo apt-get -f install和/或sudo dpkg --configure -a

  4. 如果失败,则需要手动删除软件包。 这可能涉及查找系统上的所有组件并手动删除它们。

    使用以下过程

    删除dpkg信息(见上文)

     cd /var/lib/dpkg/info sudo rm -i package_name* 

    请注意,这里不要删除超过需要的东西。

    最后删除有问题的包裹

     sudo dpkg --remove --force-remove-reinstreq package_name 

    然后你应该能够使用apt

     sudo apt-get update sudo apt-get install -f sudo apt-get upgrade 
  5. 仅在必要时查找并手动删除系统上剩余的所有文件。 这是一个手动过程,可能包括/etc或手册页或共享数据中的配置文件。 使用find或locate来识别潜在的剩余文件。

    删除系统文件时显然应该非常小心。 不要删除你不理解的东西,不要在不了解该命令的作用的情况下使用rm -Rfrm -i可能更好,因为-i选项要求确认。


重新创建此问题

您可以通过手动编辑/var/lib/dpkg/info中任何软件包的dpkg状态文件并将状态更改为已安装的一半来重现此错误消息

 sudo nano /var/lib/dpkg/info/some_package 

编辑状态行,使其读取

状态:purge reinstreq半安装

然后尝试运行apt-get

如果这不起作用,请从ppa安装包,运行apt-get clean,删除ppa,然后尝试重新安装或重新配置包。

对于长篇文章感到抱歉,但我希望这能让您深入了解此复杂错误消息的原因和解决方法“Apt / Synaptic需要重新安装软件包但无法找到它的存档”