AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 967944
Accepted
Zanna
Zanna
Asked: 2017-10-24 00:33:37 +0800 CST2017-10-24 00:33:37 +0800 CST 2017-10-24 00:33:37 +0800 CST

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

  • 772

Ubuntu 用户有时会遇到apt以下apt-get形式的错误:

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
  • 1 1 个回答
  • 1837 Views

1 个回答

  • Voted
  1. Best Answer
    Panther
    2017-10-25T12:43:07+08:002017-10-25T12:43:07+08:00

    错误“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.
    

    --配置包...|-a|--待定

              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 运行安装前/安装后脚本和其他功能。如果这些安装/删除脚本由于各种原因而失败,则包将被标记为“半安装”(或未安装/未安装以外的某种状态)。在这种不干净的状态下,您有时可能还会看到错误“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 -Rf在不了解该命令将做什么的情况下使用。rm -i可能更好,因为-i选项要求确认。


    重新创建此问题

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

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

    编辑状态行,使其显示为

    状态:purge reinstreq 已安装一半

    然后尝试运行apt-get。

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

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

    • 9

相关问题

  • 如何编写 shell 脚本来安装应用程序列表?

  • 如何查看存档中可用的软件包的所有版本?

  • 是否可以说出我安装的哪些软件包不在原版安装中?

  • 如何删除 PPA?

  • 使用 apt-get upgrade 时如何强制安装内核更新?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve