Oracle Java on EC2

Why does it have to be so ‘silly’.  All I want is to install Oracle Java from the CLI (Linux).


Here is the challenge (Oracle):

Before the file can be downloaded, you must accept the license agreement.

Well works fine from a browser…easy to accept.


  1. Download the file from a command-line web browser
  2. Download the file from a different device which has a GUI web browser and copy it to your machine
  3. Cheat the Oracle’s web server

Steps that can be used to automate this and download from the CLI using wget.

Downloading the installation file:

What the Oracle’s download page does, is to create a cookie in the browser when the user selects “Accept Licence Agreement”. This cookie is sent to the server as a HTTP Header parameter when the file is requested. But, because we are not using a browser to request the file, we will have to do it in another way which allow us to send the header information. One way is to use the wget command. This command is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, as well as retrieval through HTTP proxies. It has a parameter, –header, that adds header information to the request. Given this information, all we need to do is to run the following command to download the Java 8 JDK:

WARNING: By using this method, you are still agreeing with the Oracle Binary Code License Agreement for the Java SE.

wget c nocookies nocheckcertificate header “Cookie:; oraclelicense=accept-securebackup-cookie”” outputdocument=“jdk-8u5-linux-x64.rpm”

The otn-pub within the url is critical as this is not the link displayed on the oracle site.  Replace 8u5-b13/jdk-8u5-linux-x64.rpm  with whatever version is required.


sudo rpm i jdk8u5linuxx64.rpm

Register the environment variable JAVA_HOME and define the command java to the new installation (in case you have other versions installed, such as OpenJDK or an older Oracle’s Java version).

sudo alternatives install /usr/bin/java java /usr/java/default/bin/java 20000

export JAVA_HOME=/usr/java/default


java version

Version is still incorrect?

Remove current default:

sudo alternatives remove java/usr/lib/jvm/jre1.7.0openjdk.x86_64/bin/java

sudo alternatives install /usr/bin/java java /usr/java/default/bin/java 20000

Select an available Java version:

sudo alternatives install /usr/bin/java java /usr/java/default/bin/java 20000

echo 2 | /usr/sbin/alternatives config java

Depending on your use of the EC2 instance you may need to set child links:


 Hope this helps


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s