Java Ubuntu:未安装 Oracle JDK 8

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32758465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 13:01:35  来源:igfitidea点击:

Ubuntu: Oracle JDK 8 is NOT installed

javaubuntujava-8apt-get

提问by batroudoroch

I've installed oracle JDK-8 on ubuntu 14.04 manually. but whenever I want to install a package that needs jdk8, apt-get tries to install jdk 8 again. my country is restricted so oracle server won't allow me to download jdk8.

我已经在 ubuntu 14.04 上手动安装了 oracle JDK-8。但是每当我想安装需要 jdk8 的软件包时,apt-get 都会尝试再次安装 jdk 8。我的国家受到限制,所以 oracle 服务器不允许我下载 jdk8。

$java -version

java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

and the results of apt-get are:

apt-get 的结果是:

download failed
Oracle JDK 8 is NOT installed.
dpkg: error processing package oracle-java8-installer (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 oracle-java8-installer
E: Sub-process /usr/bin/dpkg returned an error code (1)

with this error, apt-get won't finish the installation.

出现此错误,apt-get 将无法完成安装。

采纳答案by Tony Weddle

I suspect you've installed Oracle JDK8 using the archive, extracting to your own folder. It's probably the case that Ubuntu doesn't know that you've installed Java as the system Java and so is raising the error.

我怀疑您已经使用存档安装了 Oracle JDK8,并将其解压缩到您自己的文件夹中。可能的情况是 Ubuntu 不知道您已将 Java 安装为系统 Java,因此会引发错误。

To be honest, I'm not sure how you go about installing it for system wide use but this pagemay provide some pointers. Installing Open JDK might be the better option, but an option is also given here, and this answermight also help.

老实说,我不确定您如何安装它以供系统广泛使用,但此页面可能会提供一些指示。安装 Open JDK 可能是更好的选择,但这里也提供一个选项,这个答案也可能有所帮助。

回答by tk_

Try this,

尝试这个,

First update the apt-get repos

首先更新apt-get repos

$ sudo apt-get update

Add the java 8 repo to apt-get

将 java 8 repo 添加到 apt-get

$ sudo add-apt-repository ppa:webupd8team/java

Again update the apt-get repo

再次更新apt-get repo

$ sudo apt-get update

Finally install java 8

最后安装java 8

$ sudo apt-get install oracle-java8-installer

References:

参考资料

回答by Viktor Kruglikov

oracle-java8-installer is not able to download file. So downlaod it manually from Oracle site and put into folder /var/cache/oracle-jdk8-installer/. And try to install oracle-java8-installer again. This solved the problem for me.

oracle-java8-installer 无法下载文件。所以从Oracle站点手动下载它并放入文件夹/var/cache/oracle-jdk8-installer/。并尝试再次安装 oracle-java8-installer。这为我解决了这个问题。

Step by step:

一步步:

  • Check what file oracle-java8-installer is not able to download. You can see it in installation log. Let's suppose it's jdk-8u111-linux-x64.tar.gz
  • Googleit jdk-8u111-linux-x64.tar.gzand you'll find exact page on Oracle site where to download it from. For our example it's http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  • Download jdk-8u111-linux-x64.tar.gzfile and put in into folder /var/cache/oracle-jdk8-installer/.
  • And try to install oracle-jdk8-installer again: sudo apt-get install oracle-java8-installerInstallation should finish successfully.
  • 检查 oracle-java8-installer 无法下载的文件。您可以在安装日志中看到它。让我们假设它是jdk-8u111-linux-x64.tar.gz
  • 谷歌一下jdk-8u111-linux-x64.tar.gz,你会在 Oracle 网站上找到确切的页面,从哪里下载它。对于我们的示例,它是http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  • 下载jdk-8u111-linux-x64.tar.gz文件并放入文件夹中/var/cache/oracle-jdk8-installer/
  • 并再次尝试安装 oracle-jdk8-installer:sudo apt-get install oracle-java8-installer安装应该成功完成。

回答by Ivan Lee

the first step:

第一步:

sudo apt-get remove oracle-java8-installer

to clean up the failure installation of java8 perviously.

清理以前安装java8失败的问题。

the second step:

第二步:

sudo apt-get install oracle-java8-installer

to reinstall Java8

重新安装Java8

回答by mdeora

One of the possible reasons and solution could be, that the version of the java package is updated with the possible vulnerability patch fix, and that needs to be updated in the PPA. I faced this when installing on ubuntu 16.04.

可能的原因和解决方案之一可能是,java 包的版本已使用可能的漏洞补丁修复进行了更新,并且需要在 PPA 中进行更新。我在 ubuntu 16.04 上安装时遇到了这个问题。

If the specific download error is that java download link is 404, than mostly this solution will work.

如果特定的下载错误是 java 下载链接为 404,则 此解决方案通常会起作用

Please remember to update the versions accordingly.

请记住相应地更新版本。

回答by Sagar Chawla

This worked for me:

这对我有用:

  • First, go to below path:

    cd /var/lib/dpkg/info

  • 首先,转到以下路径:

    cd /var/lib/dpkg/info

Run all 4 sedcommands:

运行所有 4 个sed命令:

sudo sed -i 's|JAVA_VERSION=8u161|JAVA_VERSION=8u172|' oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u172-b11/a58eab1ec242421181065cdc37240b08/|' oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="6dbc56a0e3310b69e91bb64db63a485bd7b6a8083f08e48047276380a0e2021e"|SHA256SUM_TGZ="28a00b9400b6913563553e09e8024c286b506d8523334c93ddec6c9ec7e9d346"|' oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_161|J_DIR=jdk1.8.0_172|' oracle-java8-installer.*
  • Second:

    sudo apt-get install oracle-java8-installer

  • 第二:

    sudo apt-get install oracle-java8-installer

回答by shoom

If OpenJDK also OK for you, try to use sdkmanfor installing all java staff) It's a very cool tool.

如果 OpenJDK 也适合您,请尝试使用sdkman安装所有 Java 人员)这是一个非常酷的工具。