Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to install java8 using PPA repository on ubuntu 16.04

Getting below errors from 17-jan 2018:

--2018-01-18 09:59:52--  http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz
Resolving download.oracle.com (download.oracle.com)... 104.94.43.14
Connecting to download.oracle.com (download.oracle.com)|104.94.43.14|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily

--2018-01-18 09:59:52--  http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz?AuthParam=1516269712_4add28cbea8b722e5136a80b8de32670
Connecting to download.oracle.com (download.oracle.com)|104.94.43.14|:80... connected.
HTTP request sent, awaiting response... 404 Not Found

Commands we are executing to install java8 on Ubuntu:

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

getting similar error for java7 and java9 as well.

Please take a look into this issue and let me know if any workaround

like image 278
Abhijeet Kale Avatar asked Jan 18 '18 10:01

Abhijeet Kale


2 Answers

It seems, Oracle changed the policy to remove outdated updates pretty quickly these days (in this case: 8u151/8u152). Sadly, the ppa:webupd8team/java-maintainers did not yet publish an updated version of their packages which matches the latest JDK release (8u161). They should, however, do this to change the download URLs for the respective JDK archives (as published by Oracle).

In case you need an urgent update and/or as a "temporary" workaround you can get the latest version of Oracle JDK via the following steps:

  1. Create a tmp directory in your user home and download the current JDK update 161 via wget.

    mkdir ~/tmp
    cd tmp
    wget --continue --no-check-certificate --header "Cookie: oraclelicense=a" 'http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz' 
    
  2. Unpack it in the tmpdirectory

    tar -xf jdk-8u161-linux-x64.tar.gz 
    
  3. Clear out the old installation and move the contents extracted into jdk1.8... to the system-wide JDK installation directory:

    sudo rm -R /usr/lib/jvm/java-8-oracle 
    sudo mkdir /usr/lib/jvm/java-8-oracle
    sudo mv jdk1.8.0_161/* /usr/lib/jvm/java-8-oracle
    sudo chown -R root:root /usr/lib/jvm/java-8-oracle
    
  4. Run:

    sudo /etc/profile.d/jdk.sh
    
  5. Check the current java version by running:

    java -version
    

Note well: The URL used in step 1 points to a x64 JDK assuming a non-32bit system environment. You can easily change it by inspecting the official download page by Oracle.

Hope it helps (as a workaround).

like image 114
MWiesner Avatar answered Nov 14 '22 17:11

MWiesner


There is one more workaround for this problem that I've used previously. For me this was simpler approach:

apt-get install oracle-java8-installer -y oracle-java8-set-default -y || true
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.*
apt-get install oracle-java8-installer oracle-java8-set-default -y

Initially solution was published here: https://ubuntuforums.org/showthread.php?t=2374686&page=4&p=13731177#post13731177

like image 20
Bojan Trajkovski Avatar answered Nov 14 '22 19:11

Bojan Trajkovski