How to Install Java 8 (JDK 1.8) on Amazon Linux: A Step-by-Step Guide


3 views

When running sudo yum update on Amazon Linux, you'll notice the system maintains Java 1.7 as the default version. This happens because:

  • The default Amazon Linux AMI repositories prioritize stability over latest versions
  • OpenJDK 1.7 is marked as a system dependency for some Amazon services
  • The yum package manager won't automatically upgrade major Java versions

The cleanest method is using Amazon's own repository:

sudo amazon-linux-extras install java-openjdk11

For those specifically needing JDK 1.8 (Java 8), use:

sudo amazon-linux-extras enable java-openjdk11
sudo yum install java-1.8.0-openjdk-devel

If you need Oracle JDK or specific versions:

wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" \
https://download.oracle.com/otn-pub/java/jdk/8u291-b10/d7fc238d0cbf4b0dac67be84580cfb4b/jdk-8u291-linux-x64.tar.gz

sudo mkdir /usr/java
sudo tar -xzvf jdk-8u291-linux-x64.tar.gz -C /usr/java/

After installation, configure the system to use Java 8:

sudo alternatives --config java
sudo alternatives --config javac

Verify with:

java -version
javac -version

Problem: Java version doesn't change after installation
Solution: Check environment variables and alternatives:

echo $JAVA_HOME
update-alternatives --display java

If you're running an older version of Java (like 1.7.0_75) on Amazon Linux and need to upgrade to Java 1.8 for compatibility with modern applications, you've likely encountered the frustrating limitation where sudo yum update doesn't pull in the newer version. This happens because Amazon Linux's default repositories often lag behind the latest Java releases.

First, verify your current Java installation:

java -version

This should output something like:

java version "1.7.0_75"
OpenJDK Runtime Environment (amzn-2.5.4.0.53.amzn1-x86_64 u75-b13)
OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)

Amazon Linux uses a different package name for Java 8. Here's how to install it:

sudo yum install java-1.8.0-openjdk-devel

If you want the full JDK (not just JRE), use:

sudo yum install java-1.8.0-openjdk

After installation, you'll need to configure the system to use Java 8 by default:

sudo alternatives --config java

You'll see output like this:

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
   2           /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java

Enter to keep the current selection[+], or type selection number: 

Enter 2 to select Java 8, then verify:

java -version

If you specifically need Oracle's JDK instead of OpenJDK:

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm"
sudo yum localinstall jdk-8u201-linux-x64.rpm

If you encounter issues with the alternatives system, try:

sudo alternatives --install /usr/bin/java java /usr/lib/jvm/jre-1.8.0/bin/java 20000
sudo alternatives --set java /usr/lib/jvm/jre-1.8.0/bin/java

Create a simple test file HelloWorld.java:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World from Java " + 
            System.getProperty("java.version"));
    }
}

Compile and run:

javac HelloWorld.java
java HelloWorld

You should see output confirming Java 1.8 is running.