问题描述
我正在运行Ubuntu 16.04 Xenial桌面,64位,并且想要安装openjdk-9-jdk
(Java 9开发工具包)。 universe
存储库中提供的版本为9~b114-0ubuntu1
。
运行安装命令成功安装依赖项(请参阅下文,包括程序包openjdk-9-jdk-headless
),但由于所述依赖项提供的文件也存在于有问题的程序包中,因此无法安装所请求的程序包:
dpkg: error processing archive /var/cache/apt/archives/openjdk-9-jdk_9~b114-0ubuntu1_amd64.deb (--unpack):
trying to overwrite '/usr/lib/jvm/java-9-openjdk-amd64/include/linux/jawt_md.h', which is also in package openjdk-9-jdk-headless:amd64 9~b114-0ubuntu1
这是完整的输出:
$ sudo apt install openjdk-9-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
ca-certificates-java libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev
libxt-dev openjdk-9-jdk-headless openjdk-9-jre openjdk-9-jre-headless x11proto-core-dev x11proto-input-dev x11proto-kb-dev
xorg-sgml-doctools xtrans-dev
Suggested packages:
libice-doc libsm-doc libxcb-doc libxt-doc openjdk-9-demo openjdk-9-source visualvm icedtea-8-plugin fonts-ipafont-gothic
fonts-ipafont-mincho ttf-wqy-microhei | ttf-wqy-zenhei fonts-indic
The following NEW packages will be installed
ca-certificates-java libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev
libxt-dev openjdk-9-jdk openjdk-9-jdk-headless openjdk-9-jre openjdk-9-jre-headless x11proto-core-dev x11proto-input-dev
x11proto-kb-dev xorg-sgml-doctools xtrans-dev
0 to upgrade, 19 to newly install, 0 to remove and 0 not to upgrade.
Need to get 183 MB/187 MB of archives.
After this operation, 326 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://ftp.uni-stuttgart.de/ubuntu xenial/main amd64 ca-certificates-java all 20160321 [12,9 kB]
Get:2 http://ftp.uni-stuttgart.de/ubuntu xenial/universe amd64 openjdk-9-jre-headless amd64 9~b114-0ubuntu1 [183 MB]
Get:3 http://ftp.uni-stuttgart.de/ubuntu xenial/universe amd64 openjdk-9-jre amd64 9~b114-0ubuntu1 [51,5 kB]
Fetched 183 MB in 2min 21s (1.293 kB/s)
Selecting previously unselected package ca-certificates-java.
(Reading database ... 210101 files and directories currently installed.)
Preparing to unpack .../ca-certificates-java_20160321_all.deb ...
Unpacking ca-certificates-java (20160321) ...
Selecting previously unselected package openjdk-9-jre-headless:amd64.
Preparing to unpack .../openjdk-9-jre-headless_9~b114-0ubuntu1_amd64.deb ...
Unpacking openjdk-9-jre-headless:amd64 (9~b114-0ubuntu1) ...
Selecting previously unselected package xorg-sgml-doctools.
Preparing to unpack .../xorg-sgml-doctools_1%3a1.11-1_all.deb ...
Unpacking xorg-sgml-doctools (1:1.11-1) ...
Selecting previously unselected package x11proto-core-dev.
Preparing to unpack .../x11proto-core-dev_7.0.28-2ubuntu1_all.deb ...
Unpacking x11proto-core-dev (7.0.28-2ubuntu1) ...
Selecting previously unselected package libice-dev:amd64.
Preparing to unpack .../libice-dev_2%3a1.0.9-1_amd64.deb ...
Unpacking libice-dev:amd64 (2:1.0.9-1) ...
Selecting previously unselected package libpthread-stubs0-dev:amd64.
Preparing to unpack .../libpthread-stubs0-dev_0.3-4_amd64.deb ...
Unpacking libpthread-stubs0-dev:amd64 (0.3-4) ...
Selecting previously unselected package libsm-dev:amd64.
Preparing to unpack .../libsm-dev_2%3a1.2.2-1_amd64.deb ...
Unpacking libsm-dev:amd64 (2:1.2.2-1) ...
Selecting previously unselected package libxau-dev:amd64.
Preparing to unpack .../libxau-dev_1%3a1.0.8-1_amd64.deb ...
Unpacking libxau-dev:amd64 (1:1.0.8-1) ...
Selecting previously unselected package libxdmcp-dev:amd64.
Preparing to unpack .../libxdmcp-dev_1%3a1.1.2-1.1_amd64.deb ...
Unpacking libxdmcp-dev:amd64 (1:1.1.2-1.1) ...
Selecting previously unselected package x11proto-input-dev.
Preparing to unpack .../x11proto-input-dev_2.3.1-1_all.deb ...
Unpacking x11proto-input-dev (2.3.1-1) ...
Selecting previously unselected package x11proto-kb-dev.
Preparing to unpack .../x11proto-kb-dev_1.0.7-0ubuntu1_all.deb ...
Unpacking x11proto-kb-dev (1.0.7-0ubuntu1) ...
Selecting previously unselected package xtrans-dev.
Preparing to unpack .../xtrans-dev_1.3.5-1_all.deb ...
Unpacking xtrans-dev (1.3.5-1) ...
Selecting previously unselected package libxcb1-dev:amd64.
Preparing to unpack .../libxcb1-dev_1.11.1-1ubuntu1_amd64.deb ...
Unpacking libxcb1-dev:amd64 (1.11.1-1ubuntu1) ...
Selecting previously unselected package libx11-dev:amd64.
Preparing to unpack .../libx11-dev_2%3a1.6.3-1ubuntu2_amd64.deb ...
Unpacking libx11-dev:amd64 (2:1.6.3-1ubuntu2) ...
Selecting previously unselected package libx11-doc.
Preparing to unpack .../libx11-doc_2%3a1.6.3-1ubuntu2_all.deb ...
Unpacking libx11-doc (2:1.6.3-1ubuntu2) ...
Selecting previously unselected package libxt-dev:amd64.
Preparing to unpack .../libxt-dev_1%3a1.1.5-0ubuntu1_amd64.deb ...
Unpacking libxt-dev:amd64 (1:1.1.5-0ubuntu1) ...
Selecting previously unselected package openjdk-9-jre:amd64.
Preparing to unpack .../openjdk-9-jre_9~b114-0ubuntu1_amd64.deb ...
Unpacking openjdk-9-jre:amd64 (9~b114-0ubuntu1) ...
Selecting previously unselected package openjdk-9-jdk-headless:amd64.
Preparing to unpack .../openjdk-9-jdk-headless_9~b114-0ubuntu1_amd64.deb ...
Unpacking openjdk-9-jdk-headless:amd64 (9~b114-0ubuntu1) ...
Preparing to unpack .../openjdk-9-jdk_9~b114-0ubuntu1_amd64.deb ...
Unpacking openjdk-9-jdk:amd64 (9~b114-0ubuntu1) ...
dpkg: error processing archive /var/cache/apt/archives/openjdk-9-jdk_9~b114-0ubuntu1_amd64.deb (--unpack):
trying to overwrite '/usr/lib/jvm/java-9-openjdk-amd64/include/linux/jawt_md.h', which is also in package openjdk-9-jdk-headless:amd64 9~b114-0ubuntu1
Processing triggers for ca-certificates (20160104ubuntu1) ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for gnome-menus (3.13.3-6ubuntu3) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu5) ...
Processing triggers for bamfdaemon (0.5.3~bzr0+16.04.20160415-0ubuntu1) ...
Rebuilding /usr/share/applications/bamf-2.index...
Processing triggers for mime-support (3.59ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.15-0ubuntu1) ...
Errors were encountered while processing:
/var/cache/apt/archives/openjdk-9-jdk_9~b114-0ubuntu1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
所以很明显这似乎是一个错误,由不正确的包装引起,而不是我身边的错误。在Launchpad上也有一些相关的错误报告,例如this report which seems to be the most important one。我订阅了那份报告,但目前还没有针对Xenial的解决方案。
因此,我的问题不是关于这个打包错误,而是如何解决这个问题并安装openjdk-9-jdk
,忽略“试图覆盖文件”错误?
最佳解决办法
您可以直接进行sudo apt-get -o Dpkg::Options::="--force-overwrite" install openjdk-9-jdk
。如果您在这里,您已经尝试了没有-o Dpkg::Options::="--force-overwrite"
的安装,并且您知道哪些文件将被静默覆盖。
次佳解决办法
当我使用dpkg
安装.deb
软件包时,我能够通过强制文件覆盖来自行解决错误。
这是我的解决方法,在Ubuntu 16.04 Xenial上安装openjdk-9-jdk
(未在其他版本上测试),尽管有关不覆盖其依赖项openjdk-9-jdk-headless
提供的文件的错误消息:
-
通常尝试安装
openjdk-9-jdk
软件包,最好使用软件包管理器apt
:sudo apt install openjdk-9-jdk
这将安装其所有依赖项,并下载二进制包文件。它现在应该存储在
/var/cache/apt/archives/openjdk-9-jdk_9~b114-0ubuntu1_amd64.deb
中,但是如果你有不同的版本,文件名的后半部分可能会有所不同。请注意,我们希望此单个命令失败,并显示问题中描述的错误消息。忽略错误,我们将在接下来的步骤中处理这个问题。
-
依赖包尚未完全配置,因为
openjdk-9-jdk
的安装失败并被中止。我们现在必须手动执行此操作,只需触发所有尚未配置的软件包的配置:sudo dpkg --configure -a
-
最后,我们安装了
openjdk-9-jdk
软件包。因此,我们使用在步骤1中获得的已下载和缓存的二进制包文件。我们必须添加--force-overwrite
标志,以使包管理器忽略我们提供的双重文件并静静地覆盖它。sudo dpkg -i --force-overwrite '/var/cache/apt/archives/openjdk-9-jdk_9~b114-0ubuntu1_amd64.deb'
如果您使用的是其他版本,可能需要调整文件名,或者只需使用tab-completion输入文件名:在输入文件名到下划线(
...openjdk-9-jdk_
)后按Tab
并自动填写正确的文件名称。