Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
[Guide] Install Oracle Java (JDK) 8 on Amazon EC2 Ami

First verify the version of Java being used is not Sun Java 8 SDK

java -version

Check the latest version a build numbers in

For url, the variables should be defined as:



Get the Sun Java 8 SDK from Oracle

wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" "${java_version_with_build}/jdk-${java_version}-linux-x64.rpm"

Install Sun Java 8

sudo rpm -i jdk-${java_version}-linux-x64.rpm

Check if the default java version is set to Sun Java 8 SDK

java -version

If not then lets create one more alternative for Sun Java 8 SDK

sudo /usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.${java_base_version}.0_${java_sub_version}/bin/java 20000

Set the Sun Java 8 SDK as the default java

sudo /usr/sbin/alternatives --config java

Verify if change in SDK was done

java -version

Add the export of the java home to your .bashrc, .bash_profile, .zshrc, or any other relevant file.

export JAVA_HOME=/usr/java/default

Good article. installed java 8 in the ec2 isntance

vanatpr commented Jan 28, 2016

Very useful. The one thing I'd add is that we need to tweak that URL to reflect the latest version of JDK (since that will evolve over time). For Chrome, I went to the JDK download page, clicked that "Accept License Agreement," and did a "Copy Link Address" on the Download link to get the URL.

Oracle doesn't make it easier... for u74:

wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;"  ""

Very useful - thanks.

Please add how to setup JAVA_HOME too. Thanks
Maybe this step will help?

export JAVA_HOME=/usr/java/default

thanks mohataher

bburns commented Apr 4, 2016

This question covers upgrading to Java 8 - - apparently you can do

sudo yum install java-1.8.0
sudo /usr/sbin/alternatives --config java

Not sure how this differs from the other install instructions.

@bburns - the serverfault url adds openjdk 1.8 NOT Oracle JDK 1.8.
Some tools, like maven, I've discovered, only work with Oracle JDK. Hence this post is VERY USEFUL

amazing! Thanks so much for taking time to do this. I agree with @mohataher. If you can add the export JAVA_HOME command it would be perfect. I know the step, but a lot do not.


rtfpessoa commented Jun 26, 2016

thanks @mohataher for the suggestion. I just updated the script and parameterized the version values to be easier to use this.

ph4r05 commented Aug 18, 2016

JDK 8u101

wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" "" 

After running sudo /usr/sbin/alternatives --config java the default alternative is properly set as my new java 8, but reverts back to the previous ava 7 openJDK after reboot. Any idea on how to persist the changes?

hopewise commented Nov 22, 2016

What's the id of the AMI used?

snow01 commented Nov 24, 2016

JDK 8u111

wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" ""

tml commented Jan 18, 2017

JDK 8u121-b13

wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" ''

artscii commented Mar 18, 2017

thanks, seems to have worked for far.

Seems as though the URL must include some key signature to work. The key for JDK 8u131b11 is (obviously) different from the last one poasted about. This is the URL link that worked for this version:

Need to figure out a way to automate this...

snow01 commented Jun 25, 2017

JDK 8u131-b11

wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" ""

JDK 8u144-b01

wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" \

I think the quotes need to come off the url? (missing schema problem)?

sumelio commented Oct 31, 2017

Think you, very useful

senisas commented Nov 4, 2017

Thanks, very useful
Java SE Development Kit 8u151
wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" ""

albogdano commented Nov 16, 2017

JDK 9.0.1

wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" \

m1schka commented Feb 8, 2018

8u151 doesn't work anymore, here is the new one for 8u162:

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie" ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment