Can't install Oracle Java 8 in Ubuntu 16.04

This problem occurred again because version 161 has been archived. This version is referenced currently by the PPA. You can use the following commands to update the reference to 172 (171+bug fixes, refer Oracle's Java Downloads1):

cd /var/lib/dpkg/info

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

and then run

sudo apt-get install oracle-java8-installer

1 Java SE 8u172 is a patch-set update, including all of 8u171 plus additional bug fixes (described in the release notes).


According to this thread on Ubuntu Forums it seems to be a problem on WebUpd8's side.

Until they fix it, install it manually:

https://docs.oracle.com/javase/8/docs/technotes/guides/install/linux_jdk.html


Looks like the problem is that the PPA is trying to download java8U144 which is now an archived version so the URL is different (accessible via http://download.oracle.com/otn/ not http://download.oracle.com/otn-pub/)

The only versions that aren't archived and accessible via otn-pub are 151 and 152.

You can use this temporary workaround, until they fix this on their side.

switch to dpkg directory

cd /var/lib/dpkg/info

Then run the following commands :-

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