无法通过 apt-get 安装任何软件包

无法通过 apt-get 安装任何软件包

所以我的问题很容易描述:我无法在 Ubuntu 安装中安装任何东西。apt-get在我尝试修复我遇到的一些其他软件包错误后,它停止工作了。现在我无处可去。

让我试着解释一下我是如何陷入这种境地的……

我试图安装maven2。我安装了sudo apt-get install maven2,但没有成功。它告诉我git-core最后缺少一个新行。所以我所做的就是查找这个错误并尝试修复它。我最终找到了一个 Python 脚本,它可以向文件中添加新行/var/lib/dpkg/info。这时一切都变得更糟了……什么都行不通了,错误更多了!

这是 Python 脚本:

import os

dpkg_path = '/var/lib/dpkg/info/'
paths = os.listdir(dpkg_path)
for path in paths:
    path = dpkg_path + path
    f = open(path, 'a+')
    data = f.read()
    if len(data) > 1 and data[-1:] != '\n':
        f.write('\n')
        print 'added newline character to:', path
    f.close()  

现在,当我尝试maven通过安装时sudo apt-get install maven(我将maven2这些错误归咎于此,因此我只尝试了maven),我收到以下错误:

Fetched 49.5 MB in 2min 7s (387 kB/s): error processing package dpkg (--configure): ⠀package dpkg is not ready for configuration cannot configure (current status `half-installed') Errors were encountered while processing: ⠀dpkg E: Sub-process /usr/bin/dpkg returned an error code (1)

还有一些其他apt-get命令我暂时想不起来了,它们输出了更长的错误。如果我再次遇到它们,我会更新这个问题。

我该怎么做才能修复此问题?


编辑

我按照评论部分的要求进行了操作(尝试安装maven然后运行sudo apt-get install -f,这是终端中的整个输出:

bash: /etc/bash_completion.d/git: No such file or directory
dugi@Dugi:~$ sudo apt-get install maven
[sudo] password for dugi: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libantlr-java libcommons-validator-java libdoxia-sitetools-java
  libjdependency-java libmaven-archiver-java libmaven-clean-plugin-java
  libmaven-compiler-plugin-java libmaven-dependency-tree-java
  libmaven-filtering-java libmaven-install-plugin-java
  libmaven-jar-plugin-java libmaven-plugin-tools-java
  libmaven-reporting-impl-java libmaven-resources-plugin-java
  libmaven-shade-plugin-java libplexus-compiler-java libplexus-digest-java
  libplexus-velocity-java libwerken.xpath-java velocity
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  libaether-java libaopalliance-java libasync-http-client-java libcdi-api-java
  libcglib-java libgeronimo-interceptor-3.0-spec-java libguice-java
  libjackrabbit-java libjcommander-java libmaven-parent-java libnetty-java
  libplexus-classworlds2-java libplexus-cli-java libplexus-containers1.5-java
  libplexus-utils2-java libsisu-guice-java libsisu-ioc-java libwagon2-java
  libyaml-snake-java testng
Suggested packages:
  libaopalliance-java-doc libasync-http-client-java-doc libjcommander-java-doc
  libplexus-classworlds2-java-doc libplexus-cli-java-doc
  libplexus-utils2-java-doc
The following NEW packages will be installed:
  libaether-java libaopalliance-java libasync-http-client-java libcdi-api-java
  libcglib-java libgeronimo-interceptor-3.0-spec-java libguice-java
  libjackrabbit-java libjcommander-java libmaven-parent-java libnetty-java
  libplexus-classworlds2-java libplexus-cli-java libplexus-containers1.5-java
  libplexus-utils2-java libsisu-guice-java libsisu-ioc-java libwagon2-java
  libyaml-snake-java maven testng
0 upgraded, 21 newly installed, 0 to remove and 129 not upgraded.
78 not fully installed or removed.
Need to get 0 B/49.5 MB of archives.
After this operation, 12.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
dpkg: error processing package dpkg (--configure):
 package dpkg is not ready for configuration
 cannot configure (current status `half-installed')
Errors were encountered while processing:
 dpkg
E: Sub-process /usr/bin/dpkg returned an error code (1)
dugi@Dugi:~$ sudo apt-get install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  fop java-wrappers libantlr-java libatinject-jsr330-api-java libbatik-java
  libclassworlds-java libcommons-configuration-java libcommons-io-java
  libcommons-jexl2-java libcommons-jxpath-java libcommons-net2-java
  libcommons-validator-java libcommons-vfs-java libdom4j-java libdoxia-java
  libdoxia-sitetools-java libfop-java libganymed-ssh2-java libguava-java
  libhttpclient-java libhttpcore-java libitext1-java libjaxen-java
  libjdependency-java libjdom1-java libjetty-java libjsoup-java libjsr305-java
  libmaven-archiver-java libmaven-clean-plugin-java
  libmaven-compiler-plugin-java libmaven-dependency-tree-java
  libmaven-filtering-java libmaven-install-plugin-java
  libmaven-jar-plugin-java libmaven-plugin-tools-java
  libmaven-reporting-impl-java libmaven-resources-plugin-java
  libmaven-scm-java libmaven-shade-plugin-java libmaven2-core-java
  libmodello-java libnetbeans-cvsclient-java libplexus-ant-factory-java
  libplexus-archiver-java libplexus-bsh-factory-java libplexus-build-api-java
  libplexus-cipher-java libplexus-classworlds-java libplexus-compiler-java
  libplexus-container-default-java libplexus-containers-java
  libplexus-digest-java libplexus-i18n-java libplexus-interactivity-api-java
  libplexus-interpolation-java libplexus-io-java libplexus-sec-dispatcher-java
  libplexus-utils-java libplexus-velocity-java libqdox-java libslf4j-java
  libwagon-java libwerken.xpath-java libxbean-java libxmlgraphics-commons-java
  libxpp2-java libxpp3-java velocity
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 129 not upgraded.
78 not fully installed or removed.
Need to get 0 B/41.3 MB of archives.
After this operation, 0 B of additional disk space will be used.
dpkg: error processing package dpkg (--configure):
 package dpkg is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libbsh-java (--configure):
 package libbsh-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package bsh (--configure):
 package bsh is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libjaxp1.3-java (--configure):
 package libjaxp1.3-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libxalan2-java (--configure):
No apport report written because MaxReports is reached already
                                                              No apport report written because MaxReports is reached already
                                            No apport report written because MaxReports is reached already
                           package libxalan2-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libbsf-java (--configure):
 package libbsf-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libavalon-framework-java (--configure):
 package libavalon-framework-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libcommons-io-java (--configure):
 package libcommons-io-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package java-wrappers (--configure):
 package java-wrappers is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libbatik-java (--configure):
 package libbatik-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libxmlgraphNo apport report written because MaxReports is reached already
                        No apport report written because MaxReports is reached already
      No apport report written because MaxReports is reached already
                                                                    No apport report written because MaxReports is reached already
                                                  No apport report written because MaxReports is reached already
                                No apport report written because MaxReports is reached already
              No apport report written because MaxReports is reached already
                                                                            ics-commons-java (--configure):
 package libxmlgraphics-commons-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libfop-java (--configure):
 package libfop-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package fop (--configure):
 package fop is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libantlr-java (--configure):
 package libantlr-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libatinject-jsr330-api-java (--configure):
 package libatinject-jsr330-api-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libclassworlds-java (--configure):
 package libclassworlds-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: erNo apport report written because MaxReports is reached already
                                                                      No apport report written because MaxReports is reached already
                                                    No apport report written because MaxReports is reached already
                                  No apport report written because MaxReports is reached already
                No apport report written because MaxReports is reached already
                                                                              No apport report written because MaxReports is reached already
                                                            ror processing package libcommons-configuration-java (--configure):
 package libcommons-configuration-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libcommons-jexl2-java (--configure):
 package libcommons-jexl2-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libcommons-jxpath-java (--configure):
 package libcommons-jxpath-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libcommons-net2-java (--configure):
 package libcommons-net2-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libcommons-validator-java (--configure):
 package libcommons-validator-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libcommons-vfs-java (--configure):
 package libcommNo apport report written because MaxReports is reached already
                                                                              No apport report written because MaxReports is reached already
                                                            No apport report written because MaxReports is reached already
                                          No apport report written because MaxReports is reached already
                        No apport report written because MaxReports is reached already
      No apport report written because MaxReports is reached already
                                                                    No apport report written because MaxReports is reached already
                                                  ons-vfs-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libjaxen-java (--configure):
 package libjaxen-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libxpp2-java (--configure):
 package libxpp2-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libxpp3-java (--configure):
 package libxpp3-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libdom4j-java (--configure):
 package libdom4j-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libhttpcore-java (--configure):
 package libhttpcore-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libhttpclient-java (--configure):
 package libhNo apport report written because MaxReports is reached already
                                                                           No apport report written because MaxReports is reached already
                                                         No apport report written because MaxReports is reached already
                                       No apport report written because MaxReports is reached already
                     No apport report written because MaxReports is reached already
   No apport report written because MaxReports is reached already
                                                                 ttpclient-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libitext1-java (--configure):
 package libitext1-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package liblog4j1.2-java (--configure):
 package liblog4j1.2-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libplexus-interpolation-java (--configure):
 package libplexus-interpolation-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libplexus-utils-java (--configure):
 package libplexus-utils-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libplexus-container-default-java (--configure):
 package libplexus-container-default-java is not ready for configuration
 cannot configure (current status `half-inNo apport report written because MaxReports is reached already
                        No apport report written because MaxReports is reached already
      No apport report written because MaxReports is reached already
                                                                    No apport report written because MaxReports is reached already
                                                  No apport report written because MaxReports is reached already
                                No apport report written because MaxReports is reached already
              stalled')
dpkg: error processing package libjsr305-java (--configure):
 package libjsr305-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libguava-java (--configure):
 package libguava-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libplexus-classworlds-java (--configure):
 package libplexus-classworlds-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libxbean-java (--configure):
 package libxbean-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libplexus-containers-java (--configure):
 package libplexus-containers-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libplexus-i18n-java (--configure):
 package libplexus-i18n-java is not ready for conNo apport report written because MaxReports is reached already
                               No apport report written because MaxReports is reached already
             No apport report written because MaxReports is reached already
                                                                           No apport report written because MaxReports is reached already
                                                         No apport report written because MaxReports is reached already
                                       No apport report written because MaxReports is reached already
                     No apport report written because MaxReports is reached already
   figuration
 cannot configure (current status `half-installed')
dpkg: error processing package libdoxia-java (--configure):
 package libdoxia-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libexcalibur-logkit-java (--configure):
 package libexcalibur-logkit-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libjdom1-java (--configure):
 package libjdom1-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libwerken.xpath-java (--configure):
 package libwerken.xpath-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package velocity (--configure):
 package velocity is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libplexus-velocity-java (--configure):
 package libplexuNo apport report written because MaxReports is reached already
                                                                               No apport report written because MaxReports is reached already
                                                             No apport report written because MaxReports is reached already
                                           No apport report written because MaxReports is reached already
                         No apport report written because MaxReports is reached already
       No apport report written because MaxReports is reached already
                                                                     s-velocity-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libdoxia-sitetools-java (--configure):
 package libdoxia-sitetools-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libganymed-ssh2-java (--configure):
 package libganymed-ssh2-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libjdependency-java (--configure):
 package libjdependency-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libslf4j-java (--configure):
 package libslf4j-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libjetty-java (--configure):
 package libjetty-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: error processing package libjsoup-java (--configure):
 package libjsoup-java is not ready for configuration
 cannot configure (current status `half-installed')
dpkg: too many errors, stopping
Errors were encountered while processing:
 dpkg
 libbsh-java
 bsh
 libjaxp1.3-java
 libxalan2-java
 libbsf-java
 libavalon-framework-java
 libcommons-io-java
 java-wrappers
 libbatik-java
 libxmlgraphics-commons-java
 libfop-java
 fop
 libantlr-java
 libatinject-jsr330-api-java
 libclassworlds-java
 libcommons-configuration-java
 libcommons-jexl2-java
 libcommons-jxpath-java
 libcommons-net2-java
 libcommons-validator-java
 libcommons-vfs-java
 libjaxen-java
 libxpp2-java
 libxpp3-java
 libdom4j-java
 libhttpcore-java
 libhttpclient-java
 libitext1-java
 liblog4j1.2-java
 libplexus-interpolation-java
 libplexus-utils-java
 libplexus-container-default-java
 libjsr305-java
 libguava-java
 libplexus-classworlds-java
 libxbean-java
 libplexus-containers-java
 libplexus-i18n-java
 libdoxia-java
 libexcalibur-logkit-java
 libjdom1-java
 libwerken.xpath-java
 velocity
 libplexus-velocity-java
 libdoxia-sitetools-java
 libganymed-ssh2-java
 libjdependency-java
 libslf4j-java
 libjetty-java
 libjsoup-java
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)
dugi@Dugi:~$ 

答案1

以下是撤消更改的脚本:

     #!/bin/sh
     files="/var/lib/dpkg/info/*"
     mkdir /tmp/backup
     for i in $files
     do
        cp $i /tmp/backup                # save file in case of errors
        sed '$d' $i > $i.out             # remove last line and put result in .out
        mv  $i.out $i                    # rename file as original
     done

将脚本保存在文件中并执行:

     sudo sh file

为了验证结果,请尝试

     diff -r /var/lib/dpkg/info /tmp/backup

当且仅当 diff 仅显示空白行时,重试:

     sudo dpkg --configure -a

否则从 /tmp/backup 恢复文件

相关内容