27

I was wondering if anyone knows if it will be possible for me to install Java 8 on an EC2 instance. My application is packed as a fat jar with embedded jetty, so the Java 8 runtime alone should be sufficient.

I'm not too familiar with Linux, and I saw that they only had Java 7 support on the default AMI. Is there a simple command I can run to update to Java 8?

Rune Aamodt
  • 2,551
  • 2
  • 23
  • 27

6 Answers6

66

check Java current version

java -version

install Java 1.8

sudo yum install java-1.8.0

change the Java version

sudo alternatives --config java
Damith Ganegoda
  • 4,100
  • 6
  • 37
  • 46
19

Java 8 may not be available out-of-the-box on the AMI that you are looking for. However, you can always install it once the instance is created.

e.g. Check this post which explains how to install java 8 on Ubuntu OR check this post which explains how to install Java 8 on RHEL/Fedora/CentOS.

slayedbylucifer
  • 22,878
  • 16
  • 94
  • 123
  • 11
    I am running a free t2.micro 64-bit EC2 instance. Amazon's AMI linux comes with OpenJDK. The command `java -version` showed AMI had Java 7 out-of-the-box. To upgrade to 8 I did 1) installed OpenJDK 8 `sudo yum install java-1.8.0-openjdk-devel` 2) switched to 8 `sudo alternatives --config java`. The command `java -version` then reported openjdk version "1.8.0_45" etc. – Steve Jun 10 '15 at 01:30
  • The above didn't work for me, but "sudo yum provides java" gave me a list of available packages, and I was able to install Java 11 with "sudo yum install java-11-amazon-corretto-11.0.5+10-1.amzn2.x86_64" – user998303 Dec 15 '19 at 20:33
17

Installing JDK 8:

Step 1: Check the Java Version

     java -version

Step 2: Download RPM package of Oracle JDK (8u121)

     wget --no-check-certificate --no-cookies --header "Cookie:oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u141-b15/336fa29ff2bb4ef291e347e091f7f4a7/jdk-8u141-linux-x64.rpm

Step 4: Install JDK 8

     sudo yum install -y jdk-8u141-linux-x64.rpm

Step 5: Verify oracle JDK version

     java -version

Installing JRE 1.8

   sudo yum install java-1.8.0

change the Java version

  sudo alternatives --config java
Praneeth
  • 529
  • 5
  • 8
2
  1. Donwload Linux version of JRE from below link to your windows machine as it has browser. Note that if you are using this EC2 instance as server you just need JRE and not complete JDK. https://www.oracle.com/technetwork/java/javase/downloads/server-jre8-downloads-2133154.html
  2. Tranfer downloaded .tar.gz file using winscp to your EC2 instance.
  3. Run "tar zxvf jre-8uversion-linux-i586.tar.gz" on your EC2 instance. For more info https://docs.oracle.com/javase/8/docs/technotes/guides/install/linux_jre.html#CFHBHAGI
Vikky
  • 1,123
  • 14
  • 16
2

This question is old but this may help with Java 11. If anybody is interested in installing Java JDK 11, I run

sudo amazon-linux-extras install java-openjdk11

in my EC2 instance with Amazon Linux. I got it from here: https://tecadmin.net/install-java-on-amazon-linux/

rodolk
  • 5,606
  • 3
  • 28
  • 34
0

You can install Amazon Corretto 8 as either the runtime environment (JRE) or the full development environment (JDK). The development environment includes the runtime environment.

sudo yum install java-11-amazon-corretto -y

You can follow the AWS official document from here: https://docs.aws.amazon.com/corretto/latest/corretto-8-ug/amazon-linux-install.html