简体   繁体   中英

JDK 8 is NOT installed - ERROR 404: Not Found

Since yesterday, I've been trying to install the JDK8 on my Ubuntu machine, but it has been failing constantly.

I've been trying to run the commands:

sudo add-apt-repository ppa:webupd8team/java -y
sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default

But I can't continue because when running the command sudo apt-get install oracle-java8-installer all I get is:

...
Connecting to download.oracle.com (download.oracle.com)|23.215.130.99|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-10-18 11:07:34 ERROR 404: Not Found.

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
...

My Setup is a 64-bit Ubuntu 14.04.

After a lot of googling around I found a answer on the Ubuntu forum .

Basically, the problem seems to be that there is a new version of java and the installer wasn't updated to reference it.

If your machine is a Linux x64 with an AMD64 processor, and you need the latest Java8 version, this can be easily fixed by running these commands (Credit for the original version goes to g1zmo2 and this updated version goes to @stoneLeaf):

cd /var/lib/dpkg/info
sudo sed -i 's|JAVA_VERSION=8u191|JAVA_VERSION=8u201|' oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/|' oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ=.*|SHA256SUM_TGZ="cb700cc0ac3ddc728a567c350881ce7e25118eaf7ca97ca9705d4580c506e370"|' oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_191|J_DIR=jdk1.8.0_201|' oracle-java8-installer.*

And then running the JDK 8 installer commands like you normally would =):

sudo apt-get update
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default

If your machine is not a Linux x64 AMD64 or you are looking for Java 9 , well, you are in luck. Today is the day you'll learn to fix your java installer for your own needs.

For the purposes of this tutorial, we'll assume you want Java 8u181 and you had previously installed Java 8u171 (because that's what I have).

First, I need you to go to Java's JDK Downloads page (For Java8, go here , click the "Downloads" tab , and then the "Java SE 8u181" link ).

Now, look up the JDK version you need based on your machine. In my case, my machine is running on Ubuntu 14.04 64-bit, so I need "Linux x64".

JDK版本

Copy the link that takes you to the download you need. Don't forget to accept the license agreement. In my case (Linux x64), I need: http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/jdk-8u181-linux-x64.tar.gz .

For the purposes of this tutorial, we only need the link's path: http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/ . Keep it safe; we'll need it later.

Now look up the checksum link in the page and click it .

校验和链接

This should take you to a plain html table page. Just look for the sha256 that fits your machine.

Linux x64 SHA

Again, my machine is a "Linux x64" so I need 1845567095bfbfebd42ed0d09397939796d05456290fb20a83c476ba09f991d3 , like in the picture. Copy the value, and keep it safe; we'll need it later too.

Now, open a terminal on your machine and enter the folder where the java installer file are:

cd /var/lib/dpkg/info

Great, now execute this:

sudo grep --color -P "JAVA_VERSION=[a-z0-9]+" oracle-java8-installer.config

The output should look something like this:

安装程序的java版本

This tells us what is the java version that the installer is configured to install. So to change those values easily we would run something like this:

sudo sed -i 's|JAVA_VERSION=<INSTALLER CURRENT JAVA VERSION HERE>|JAVA_VERSION=<NEW VERSION HERE>|' oracle-java8-installer.*

For our case, we are upgrading from 8u171 to 8u181 , so we would execute:

sudo sed -i 's|JAVA_VERSION=8u171|JAVA_VERSION=8u181|' oracle-java8-installer.*

Ok, now we need to update the download url.

sudo grep --color -P "PARTNER_URL=[^ ]+" oracle-java8-installer.config

安装人员的合作伙伴网址

To update it, we should execute a command like this:

sudo sed -i 's|PARTNER_URL=<INSTALLER CURRENT JAVA URL HERE>|PARTNER_URL=<NEW URL HERE>|' oracle-java8-installer.*

Remember that URL I told you to save at the start? Well, we'll need it now. Place it as your new url, like this:

sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/|' oracle-java8-installer.*

After that, we need to update the checksum. So please execute this command:

sudo grep --color -P '[^#]SHA256SUM_TGZ="[^"]+"' oracle-java8-installer.config

This prints out a couple different SHA256:

安装人员的SHA256

Notice that they are all different. We'll get back at that in a second. So, to update the SHA256, we would need to execute this command:

sudo sed -i 's|SHA256SUM_TGZ="<INSTALLER CURRENT JAVA HASH HERE>"|SHA256SUM_TGZ="<NEW JAVA HASH>"|' oracle-java8-installer.*

But how do we know which of the current Java hashes to replace? Well, we need to find out our processor's architecture:

dpkg --print-architecture

In my case, this will output amd64 . This means I should grab the second link. How do I know this? Well, I read the source code ( sudo gedit oracle-java8-installer.config ), so trust me on this:

  • If your architecture is i386 , i586 or i686 , grab the first one.
  • If amd64 , grab the second one.
  • If armv7l or armv6l , grab the third one.
  • If armv8l , arm64 or aarch64 , grab the fourth one.
  • If none of the above, you are out of luck...

So, as mine is amd64 , using the new hash we obtained from Java's website, I would execute:

sudo sed -i 's|SHA256SUM_TGZ="b6dd2837efaaec4109b36cfbb94a774db100029f98b0d78be68c27bec0275982"|SHA256SUM_TGZ="1845567095bfbfebd42ed0d09397939796d05456290fb20a83c476ba09f991d3"|' oracle-java8-installer.*

Finally, we need to modify the installers JDK directory name, so execute this to find the current one:

sudo grep --color -P "J_DIR=[^ ]+" oracle-java8-installer.config

In my case this printed:

安装程序的JDK文件夹名称

So we would execute something like this:

sudo sed -i 's|J_DIR=<INSTALLER CURRENT JDK VERSION HERE>|J_DIR=<NEW JDK VERSION>|' oracle-java8-installer.*

Being my current version jdk1.8.0_171 , I execute:

sudo sed -i 's|J_DIR=jdk1.8.0_171|J_DIR=jdk1.8.0_181|' oracle-java8-installer.*

And... that's it. We are ready to call the java installer, yay. (phew... this took longer to type that I thought at first).


Edit5 @MinneapolisCoder9 older version of commands used from 8u181 to 8u191 (in case it comes handy to anyone, though it should have been removed with the new build files)

cd /var/lib/dpkg/info
sudo sed -i 's|JAVA_VERSION=8u181|JAVA_VERSION=8u191|' oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/|' oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="1845567095bfbfebd42ed0d09397939796d05456290fb20a83c476ba09f991d3"|SHA256SUM_TGZ="53c29507e2405a7ffdbba627e6d64856089b094867479edc5ede4105c1da0d65"|' oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_181|J_DIR=jdk1.8.0_191|' oracle-java8-installer.*

Edit4 @Glenn Smith older version of commands used from 8u171 to 8u181 (in case it comes handy to anyone, though it should have been removed with the new build files)

cd /var/lib/dpkg/info
sudo sed -i 's|JAVA_VERSION=8u171|JAVA_VERSION=8u181|' oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/|' oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="b6dd2837efaaec4109b36cfbb94a774db100029f98b0d78be68c27bec0275982"|SHA256SUM_TGZ="1845567095bfbfebd42ed0d09397939796d05456290fb20a83c476ba09f991d3"|' oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_171|J_DIR=jdk1.8.0_181|' oracle-java8-installer.*

Edit3 @Kenny Hung older version of commands used from 8u161 to 8u171 (in case it comes handy to anyone, though it should have been removed with the new build files)

cd /var/lib/dpkg/info
sudo sed -i 's|JAVA_VERSION=8u161|JAVA_VERSION=8u171|' 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/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/|' oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="6dbc56a0e3310b69e91bb64db63a485bd7b6a8083f08e48047276380a0e2021e"|SHA256SUM_TGZ="b6dd2837efaaec4109b36cfbb94a774db100029f98b0d78be68c27bec0275982"|' oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_161|J_DIR=jdk1.8.0_171|' oracle-java8-installer.*

Edit2 @Martin Šuráb/@Albert Zhong/ p-ansell 's older version of commands used from 8u151 to 8u162 (in case it comes handy to anyone, though it should have been removed with the new build files)

cd /var/lib/dpkg/info
sudo sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u162|' oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/|' oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="68ec82d47fd9c2b8eb84225b6db398a72008285fafc98631b1ff8d2229680257"|' oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_162|' oracle-java8-installer.*

Edit1 G1zmo2's older version of commands used from 8u144 to 8u152 (in case it comes handy to anyone, though it should have been removed with the new build files):

cd /var/lib/dpkg/info
sudo sed -i 's|JAVA_VERSION=8u144|JAVA_VERSION=8u152|' oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u152-b16/aa0333dd3019491ca4f6ddbe78cdb6d0/|' oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="e8a341ce566f32c3d06f6d0f0eeea9a0f434f538d22af949ae58bc86f2eeaae4"|SHA256SUM_TGZ="218b3b340c3f6d05d940b817d0270dfe0cfd657a636bad074dcabe0c111961bf"|' oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_144|J_DIR=jdk1.8.0_152|' oracle-java8-installer.*

Thanks for cavpollo's answer for JDK 8u141.

I'll give fix for JDK 8u151-1~webupd8~0 (Use JDK 8i162 instead):

cd /var/lib/dpkg/info
sudo sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u162|' oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/|' oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="68ec82d47fd9c2b8eb84225b6db398a72008285fafc98631b1ff8d2229680257"|' oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_162|' oracle-java8-installer.*

Hit this today with Oracle moving from 8u181 to 8u191. Followed @cavpollo's steps and got it working for my stuff here is the fix for 181 to 191 in case anyone needs it:

cd /var/lib/dpkg/info
sudo sed -i 's|JAVA_VERSION=8u181|JAVA_VERSION=8u191|' oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/|' oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="1845567095bfbfebd42ed0d09397939796d05456290fb20a83c476ba09f991d3"|SHA256SUM_TGZ="53c29507e2405a7ffdbba627e6d64856089b094867479edc5ede4105c1da0d65"|' oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_181|J_DIR=jdk1.8.0_191|' oracle-java8-installer.*

The following was my workaround for Ubuntu Mate 16.04 x64:

wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u152-b16/aa0333dd3019491ca4f6ddbe78cdb6d0/jdk-8u152-linux-x64.tar.gz

mkdir /opt/jdk

sudo tar -zxf jdk-8u152-linux-x64.tar.gz -C /opt/jdk

update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_152/bin/java 100

update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_152/bin/javac 100

Credit to digital ocean for the header adjustment.

Since a few days ago this workaround is obsolete due to the new java release. Instead, use this replacement:

sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u162|' oracle-java8-installer.*
sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u162-b12/0da788060d494f5095bf8624735fa2f1/|' oracle-java8-installer.*
sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="68ec82d47fd9c2b8eb84225b6db398a72008285fafc98631b1ff8d2229680257"|' oracle-java8-installer.*
sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_162|' oracle-java8-installer.*

For the update changes made on 16th April 2019 , for Linux x64 on AMD64 going from 8u201 to 8u211 add the following:

cd /var/lib/dpkg/info
sudo sed -i 's|JAVA_VERSION=8u201|JAVA_VERSION=8u211|' oracle-java8-installer.*
sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/|PARTNER_URL=https://download.oracle.com/otn/java/jdk/8u211-b12/478a62b7d4e34b78b671c754eaaf38ab/|' oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="cb700cc0ac3ddc728a567c350881ce7e25118eaf7ca97ca9705d4580c506e370"|SHA256SUM_TGZ="c0b7e45330c3f79750c89de6ee0d949ed4af946849592154874d22abc9c4668d"|' oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_201|J_DIR=jdk1.8.0_211|' oracle-java8-installer.*

In my case I don't need to use sudo but for consistency with other responses here I have left it in.

Thanks to @cavpollo

Here it is for Java 8u181 as 8u171 is no longer working:

cd /var/lib/dpkg/info
sed -i 's|JAVA_VERSION=8u171|JAVA_VERSION=8u181|' oracle-java8-installer.*
sed -i 's|J_DIR=jdk1.8.0_171|J_DIR=jdk1.8.0_181|' oracle-java8-installer.*
sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u181-b13/96a7b8442fe848ef90c96a2fad6ed6d1/|' oracle-java8-installer.*
sed -i 's|SHA256SUM_TGZ="b6dd2837efaaec4109b36cfbb94a774db100029f98b0d78be68c27bec0275982"|SHA256SUM_TGZ="1845567095bfbfebd42ed0d09397939796d05456290fb20a83c476ba09f991d3"|' oracle-java8-installer.*

And a newer version:

cd /var/lib/dpkg/info
sudo sed -i 's|JAVA_VERSION=8u161|JAVA_VERSION=8u171|' 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/8u171-b11/512cd62ec5174c3487ac17c61aaa89e8/|' oracle-java8-installer.*
sudo sed -i 's|SHA256SUM_TGZ="6dbc56a0e3310b69e91bb64db63a485bd7b6a8083f08e48047276380a0e2021e"|SHA256SUM_TGZ="b6dd2837efaaec4109b36cfbb94a774db100029f98b0d78be68c27bec0275982"|' oracle-java8-installer.*
sudo sed -i 's|J_DIR=jdk1.8.0_161|J_DIR=jdk1.8.0_171|' oracle-java8-installer.*

Adding to @cavpollo's answer, for those using Ansible, this task will get you there

- name: Patch Java installer
  shell: "{{ item }}"
  args:
    chdir: "/var/lib/dpkg/info"
  become: yes
  with_items:
    - sed -i 's|JAVA_VERSION=8u144|JAVA_VERSION=8u152|' oracle-java8-installer.*
    - sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u152-b16/aa0333dd3019491ca4f6ddbe78cdb6d0/|' oracle-java8-installer.*
    - sed -i 's|SHA256SUM_TGZ="e8a341ce566f32c3d06f6d0f0eeea9a0f434f538d22af949ae58bc86f2eeaae4"|SHA256SUM_TGZ="218b3b340c3f6d05d940b817d0270dfe0cfd657a636bad074dcabe0c111961bf"|' oracle-java8-installer.*
    - sed -i 's|J_DIR=jdk1.8.0_144|J_DIR=jdk1.8.0_152|' oracle-java8-installer.*

Let me share with you an update for JDK version 8u172

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.*

我相信oracle提供的链接不正确请尝试这个“ http://download.oracle.com/otn-pub/java/jdk/9.0.1+11/jdk-9.0.1_linux-x64_bin.tar.gz

用于下载java 8的URL中缺少.gz以上.wget --header“Cookie:oraclelicense = accept-securebackup-cookie” http://download.oracle.com/otn-pub/java/jdk/8u152 -b16 / aa0333dd3019491ca4f6ddbe78cdb6d0 / JDK-8u152-Linux的x64.tar.gz

For the lastest version(jdk-8u211-linux-x64.tar.gz), you may get a HTTP '401 Authorization Required'. My solution to this problem is as follows.

  1. Go to the official website to download the jdk-8u211-linux-x64.tar.gz( here ), you need to register an account before you download the file.
  2. Install apache2 to build a Http server.

     sudo apt-get install apache2 
  3. Move the file you just download to the /var/www/html folder because the server default root directory is /var/www/html . Now you can download the file via url(Such as http://localhost/jdk-8u211-linux-x64.tar.gz ).

  4. Update the oracle-java8-installer.

     cd /var/lib/dpkg/info sudo sed -i 's|JAVA_VERSION=8u201|JAVA_VERSION=8u211|' oracle-java8-installer.* sudo sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/|PARTNER_URL=http://localhost/|' oracle-java8-installer.* sudo sed -i 's|SHA256SUM_TGZ="cb700cc0ac3ddc728a567c350881ce7e25118eaf7ca97ca9705d4580c506e370"|SHA256SUM_TGZ="c0b7e45330c3f79750c89de6ee0d949ed4af946849592154874d22abc9c4668d"|' oracle-java8-installer.* sudo sed -i 's|J_DIR=jdk1.8.0_201|J_DIR=jdk1.8.0_211|' oracle-java8-installer.* 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM