我正在运行 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 上也有一些相关的错误报告,例如这份报告似乎是最重要的一份。我订阅了该报告,但目前还没有针对 Xenial 的解决方案。
因此我的问题是不是关于这个包装错误, 但如何解决这个问题并继续安装openjdk-9-jdk
,忽略“试图覆盖文件”错误?
答案1
您可以直接执行sudo apt-get -o Dpkg::Options::="--force-overwrite" install openjdk-9-jdk
。如果您在这里,则表示您已经尝试过不使用 进行安装,-o Dpkg::Options::="--force-overwrite"
并且您知道哪些文件将被默默覆盖。
答案2
我可以通过在安装.deb
包时强制文件覆盖来自己解决错误dpkg
。
这是我在 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输入文件名直到下划线(
...openjdk-9-jdk_
),然后按,它就会自动完成正确的文件名。