dpkg 错误:“尝试覆盖文件,该文件也在……”

dpkg 错误:“尝试覆盖文件,该文件也在……”

例如:

$ sudo apt-get install curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
bsh : Depends: libjline-java but it is not going to be installed
groovy : Depends: libjline-java but it is not going to be installed
rhino : Depends: libjline-java but it is not going to be installed
E: Unmet dependencies. 

Try 'apt-get -f install' with no packages (or specify a solution).

当我尝试安装 clojure1.3、leiningen 和其他几个包时,我遇到了相同或类似的错误。

当我尝试错误消息中的建议时,发生了以下情况:

$ sudo apt-get -f install 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  diffstat linux-headers-3.2.0-26-generic linux-headers-3.2.0-26 dh-apparmor dkms html2text libmail-sendmail-perl libsys-hostname-long-perl
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  libjline-java
Suggested packages:
  libjline-java-doc
The following NEW packages will be installed:
  libjline-java
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
23 not fully installed or removed.
Need to get 0 B/72.0 kB of archives.
After this operation, 129 kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
(Reading database ... 226243 files and directories currently installed.)
Unpacking libjline-java (from .../libjline-java_1.0-1_all.deb) ...
dpkg: error processing /var/cache/apt/archives/libjline-java_1.0-1_all.deb (--unpack):
 trying to overwrite '/usr/share/java/jline.jar', which is also in package scala 2.9.2-400
Errors were encountered while processing:
 /var/cache/apt/archives/libjline-java_1.0-1_all.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
 bsh : Depends: libjline-java but it is not installed
 groovy : Depends: libjline-java but it is not installed
 rhino : Depends: libjline-java but it is not installed
E: Unmet dependencies. Try using -f.

答案1

警告:这个答案很危险,可能会导致系统崩溃(因为这将有效地安装软件包,但当两个软件包尝试使用相同的库/文件/二进制文件时,可能会出现新的问题)。使用Avinash Raj 的回答也可以考虑报告以下错误:两个都冲突的包。


您必须强制覆盖导致问题的文件:

sudo dpkg -i --force-overwrite <file-path>

对于你来说,情况是这样的:

sudo dpkg -i --force-overwrite /var/cache/apt/archives/libjline-java_1.0-1_all.deb

运行以下命令检查所有操作是否都已修复:

sudo apt-get --fix-broken install

如果仍有问题,请使用剩余的任何步骤重新运行第一步dpkg: error processing (...)

解决方案位于webupd8

答案2

请不要去danjjl 回答直接地说,如果您遇到这种“试图覆盖”错误,很可能是您有冲突的包需要先解决。

这个问题的直接解决办法是删除不需要的冲突包,在这种情况下scala

sudo dpkg -P scala

接下来,建议向相应的软件包维护者提交错误报告。这通常意味着Conflict: package在控制文件中添加一行。

另请参阅回答有关此错误的更详细解释。

答案3

@danjjl 的命令适用于.deb文件。我发现这个命令适用于apt/ apt-get

sudo apt-get -o Dpkg::Options::="--force-overwrite" install <package-name>

答案4

dpkg --force-overwrite这里以各种形式介绍的黑客解决方法也是如此。但是dpkg-divert(8)是处理这种情况的预期方法。

相关内容