AWS EC2 Update Java

Smart Panda - Java

AWS EC2 Update Java

While working on a new Amazon EC2 Instance the default java that shows up is an openJDK version which may not necessarily be the right java for certain enterprise applications. This is a nice clean way of installing and changing to a new version of Java. In this example we are installing Oracle JDK 1.8.0 update 141. So here we go:

1. Go to Oracle’s Java Download Page and find the right rpm that you want to install: Java Download Page

2. Log into your EC2 Instance and switch to the root account

3. Execute the command: wget –no-check-certificate –no-cookies –header “Cookie:oraclelicense=accept-securebackup-cooke” {URL FROM Step 1}
– This is the command I used for Linux x64 rpm download:

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" {URL}

In order to get the URL, go to the Oracle Java Download page at: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html, accept the license agreement, and then right click on the file you wish to download and select copy link address. This will give you the {URL} you need as it will have the random key in it. For example the URL I just used was:

http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.rpm

4. Install the new Java RPM: rpm -i jdk-8u141-linux-x64.rpm

5. Check your Java Version: java -version (Will most likely show a different version than you just installed)

6. Switch to an alternate version: alternatives –config java (Select the version you just installed for me: /usr/java/jdk1.8.0_141/jre/bin/java)

7. If the version you want is not there you may need to install it as an alternative: alternatives –install /usr/java/jdk1.8.0_141/bin/java 2000

8. Check your Java Version again: java -version (It should be pointing correctly now).

Go have some fun with your newly install version of Java!