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. 

请不要直接使用danjjl答案 ,如果您遇到这种“试图覆盖”错误,可能是您需要首先解决的冲突包。

该问题的直接解决方法是删除不受欢迎的冲突包,在本例中为scala

 sudo dpkg -P scala 

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

另请参阅此答案以获取有关此错误的更详细说明。

解决运行问题

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

通过运行来检查所有内容: sudo apt-get -f install

如果您仍然遇到问题,请使用任何dpkg: error processing (...)重新运行第一步dpkg: error processing (...)剩余

在webupd8上找到解决方案

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

 sudo apt-get -o Dpkg::Options::="--force-overwrite" install  

不确定这是一个全局修复,因为我有同样的问题,但缓存中的libglx-mesa文件与Nvidia-390冲突。 我删除了文件并发出了apt install -f -y ,让它完成,然后按顺序继续进行apt updateupgradeautoremove

我在Ubuntu 18.04上执行apt dist-upgrade时遇到了错误并再次继续该过程,没有更多的问题,这似乎是“我的”修复。

命令:

 sudo su - mv /var/cache/apt/archives/libglx-mesa0_18.0.0~rc5-1ubuntu1_amd64.deb ~ apt install -f -y apt update -y apt upgrade -y apt autoremove -y apt dist-upgrade 

PS:强迫覆盖是一个坏主意,我尝试过,我很幸运。 但最好找到根本原因并修复它。 我仍然需要调查,但错误导致我将文件移出。