Another option might be running the following commands:

In order to install java 11:

sudo amazon-linux-extras install java-openjdk11

For java 8 you can try:

sudo yum install java-1.8.0-openjdk

Finally, if you want to switch between java versions run:

sudo alternatives --config java

Answer from rahimli on Stack Overflow
🌐
AWS
docs.aws.amazon.com › corretto › corretto 11 user guide › amazon corretto 11 guide for linux › amazon corretto 11 installation instructions for amazon linux 2 and amazon linux 2023
Amazon Corretto 11 Installation Instructions for Amazon Linux 2 and Amazon Linux 2023 - Amazon Corretto 11
Option 1: Install the headless Amazon Corretto 11: ... While it is recommended to use /usr/lib/jvm/java-11-amazon-corretto.<cpu_arch> location, installation may also add alternative links making installation location accessible via /etc/alternatives/jre, /etc/alternatives/jre_11 and ...
Top answer
1 of 7
68

Another option might be running the following commands:

In order to install java 11:

sudo amazon-linux-extras install java-openjdk11

For java 8 you can try:

sudo yum install java-1.8.0-openjdk

Finally, if you want to switch between java versions run:

sudo alternatives --config java

2 of 7
18

Sharing my simple working approach

Downloading the JDK

curl -LO https://corretto.aws/downloads/latest/amazon-corretto-11-x64-linux-jdk.tar.gz

note: check the ec2 instance's platform ie., x64, aarch64, x86, aarch32 etc.,because the wrong platform jdk installation will leads to /bin/java: /bin/java: cannot execute binary file

Extracting the JDK to /usr/java/

sudo tar -xvzf amazon-corretto-11-x64-linux-jdk.tar.gz -C /usr/java/

Run the below single line command to change the soft link for java files in (/usr/bin) directory

cd /usr/java/amazon-corretto-*-linux-x64/bin
for i in java javac jfr; do path=$(find `pwd`/$i -type f); echo $path; sudo alternatives --install /usr/bin/i $path 20000 ; sudo update-alternatives --config $i ; done

after the above command execution, there will be a command prompt that will ask you to choose the selection number which represents the file residing path and we should choose the number which refers to path /usr/java/amazon-corretto-*-linux-x64/bin/

The amazon-corretto jdk version may vary based on the timeline that you download. Currently the java version is 11.0.12.7.1

That's it execute java -version, you can see the java version as

openjdk version "11.0.12" 2021-07-20 LTS
OpenJDK Runtime Environment Corretto-11.0.12.7.1 (build 11.0.12+7-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.12.7.1 (build 11.0.12+7-LTS, mixed mode)
🌐
AWS re:Post
repost.aws › questions › QUyIfeuRXISUCrJPlXYKWGlw › java-11-openjdk-devel-for-amazon-linux-2
java-11-openjdk-devel for Amazon Linux 2 | AWS re:Post
January 31, 2019 - The plan at this point is to make the package available in the Amazon Linux extras repositories. ... Hello, The java-11-openjdk package is now available in the Amazon Linux 2 extras repositories.
🌐
Tenable
tenable.com › plugins › nessus › 189190
Amazon Linux 2 : java-11-amazon-corretto (ALAS-2024-2414)<!-- --> | Tenable®
The remote Amazon Linux 2 host is missing a security update. The version of java-11-amazon-corretto installed on the remote host is prior to 11.0.22+7-1. It is, therefore, affected by multiple vulnerabilities as referenced in the ALAS2-2024-2414 advisory. A vulnerability that allows an attacker ...
🌐
DEV Community
dev.to › aws-builders › install-java-11-on-amazon-linux-2-2k1i
Install Java 11 on Amazon Linux 2 - DEV Community
January 11, 2023 - Posted on Jan 11, 2023 · #aws #amazonlinux #installjava11 · Command: sudo yum update · sudo amazon-linux-extras install java-openjdk11 · Type "Y" for install packages · Wait until all packages finished install · Command: java -version ...
🌐
CloudKatha
cloudkatha.com › home › how to install openjdk 11 on amazon linux 2
How to Install OpenJDK 11 on Amazon Linux 2 - CloudKatha
August 29, 2023 - Amazon Linux 2: Amazon Linux 2 ... to install software on Linux 2. OpenJDK 11: OpenJDK 11 is the open-source implementation of version 11 of the Java SE Platform or Java 11....
🌐
Tenable
tenable.com › plugins › nessus › 166396
Amazon Linux 2 : java-11-amazon-corretto (ALAS-2022-1867)<!-- --> | Tenable®
October 21, 2022 - The remote Amazon Linux 2 host is missing a security update. The version of java-11-amazon-corretto installed on the remote host is prior to 11.0.17+8-1. It is, therefore, affected by multiple vulnerabilities as referenced in the ALAS2-2022-1867 advisory. Title: Wider MultiByte conversionsBuffer overflow is possible due to incorrect byte count (should be charactercount).
🌐
TecAdmin
tecadmin.net › install-java-on-amazon-linux
How to Install Java (JDK/JRE) on Amazon Linux – TecAdmin
April 26, 2025 - This guide provides a clear, step-by-step approach to installing Java 21, Java 17, Java 11 and Java 8 on Amazon Linux 2, ensuring you have the necessary runtime environments to compile and run Java applications.
Find elsewhere
🌐
Amazon
alas.aws.amazon.com › AL2 › ALASJAVA-OPENJDK11-2024-006.html
ALASJAVA-OPENJDK11-2024-006
Amazon Linux 2 Security Advisory: ALASJAVA-OPENJDK11-2024-006 Advisory Released Date: 2024-01-09 Advisory Updated Date: 2024-01-09 ... Vulnerability in the Oracle Java SE, Oracle GraalVM for JDK product of Oracle Java SE (component: JSSE). Supported versions that are affected are Oracle Java SE: 8u381, 8u381-perf, 11...
🌐
Tenable
tenable.com › plugins › nessus › 171853
Amazon Linux 2 : java-11-openjdk (ALASJAVA-OPENJDK11-2023-003)<!-- --> | Tenable®
February 23, 2023 - The remote Amazon Linux 2 host is missing a security update. The version of java-11-openjdk installed on the remote host is prior to 11.0.18.0.10-1. It is, therefore, affected by multiple vulnerabilities as referenced in the ALAS2JAVA-OPENJDK11-2023-003 advisory.
🌐
SITENOL
sitenol.com › home › install java on amazon linux 2 using corretto 11 – aws lightsail
Install Java on Amazon Linux 2 using Corretto 11 - AWS Lightsail
July 24, 2021 - In this tutorial, we used Corretto 11 to install Java on Amazon Linux 2. Amazon Corretto is nothing but an updated version of OpenJDK by Amazon.
🌐
Tenable
tenable.com › plugins › nessus › 138630
Amazon Linux 2 : java-11-amazon-corretto, --advisory ALAS2-202...<!-- --> | Tenable®
The remote Amazon Linux 2 host is missing a security update. The version of java-11-amazon-corretto installed on the remote host is prior to 11.0.8+10-1. It is, therefore, affected by multiple vulnerabilities as referenced in the ALAS2-2020-1464 advisory. Vulnerability in the Java SE, Java SE Embedded product of Oracle Java SE (component: Libraries).
🌐
Tenable
tenable.com › plugins › nessus › 234984
Amazon Linux 2 : java-11-openjdk (ALASJAVA-OPENJDK11-2025-012)<!-- --> | Tenable®
April 29, 2025 - The remote Amazon Linux 2 host is missing a security update. The version of java-11-openjdk installed on the remote host is prior to 11.0.7.10-4. It is, therefore, affected by multiple vulnerabilities as referenced in the ALAS2JAVA-OPENJDK11-2025-012 advisory.
🌐
DjaoDjin
djaodjin.com › blog › jenkins-upgrade-java11.blog.html
Upgrading to Java11 on Amazon Linux 2 | DjaoDjin
November 16, 2022 - $ sudo amazon-linux-extras install java-openjdk11 $ java -version openjdk version "1.8.0_332" OpenJDK Runtime Environment (build 1.8.0_332-b09) OpenJDK 64-Bit Server VM (build 25.332-b09, mixed mode) $ sudo alternatives --config java $ java -version openjdk version "11.0.16" 2022-07-19 LTS OpenJDK Runtime Environment (Red_Hat-11.0.16.0.8-1.amzn2.0.1) (build 11.0.16+8-LTS) OpenJDK 64-Bit Server VM (Red_Hat-11.0.16.0.8-1.amzn2.0.1) (build 11.0.16+8-LTS, mixed mode, sharing) $ sudo systemctl restart jenkins.service
🌐
Tenable
tenable.com › plugins › nessus › 170444
Amazon Linux 2 : java-11-amazon-corretto (ALAS-2023-1918)<!-- --> | Tenable®
January 24, 2023 - The remote Amazon Linux 2 host is missing a security update. The version of java-11-amazon-corretto installed on the remote host is prior to 11.0.18+10-1. It is, therefore, affected by multiple vulnerabilities as referenced in the ALAS2-2023-1918 advisory. Enhance DTLS performance: DTLS does ...
🌐
Tenable
tenable.com › plugins › nessus › 163322
Amazon Linux 2 : java-11-amazon-corretto (ALAS-2022-1823)<!-- --> | Tenable®
July 21, 2022 - The version of java-11-amazon-corretto installed on the remote host is prior to 11.0.16+8-1. It is, therefore, affected by multiple vulnerabilities as referenced in the ALAS2-2022-1823 advisory. Generated code produced by C1 may leak a package-private class to a class from a different package.
🌐
Tenable
tenable.com › plugins › nessus › 130234
Amazon Linux 2 : java-11-openjdk (ALAS-2019-1338) (Spectre)<!-- --> | Tenable®
October 25, 2019 - CPE: p-cpe:/a:amazon:linux:java-11-openjdk, p-cpe:/a:amazon:linux:java-11-openjdk-debug, p-cpe:/a:amazon:linux:java-11-openjdk-debuginfo, p-cpe:/a:amazon:linux:java-11-openjdk-demo, p-cpe:/a:amazon:linux:java-11-openjdk-demo-debug, p-cpe:/a:amazon:linux:java-11-openjdk-devel, p-cpe:/a:amazon:linux:java-11-openjdk-devel-debug, p-cpe:/a:amazon:linux:java-11-openjdk-headless, p-cpe:/a:amazon:linux:java-11-openjdk-headless-debug, p-cpe:/a:amazon:linux:java-11-openjdk-javadoc, p-cpe:/a:amazon:linux:java-11-openjdk-javadoc-debug, p-cpe:/a:amazon:linux:java-11-openjdk-javadoc-zip, p-cpe:/a:amazon:linux:java-11-openjdk-javadoc-zip-debug, p-cpe:/a:amazon:linux:java-11-openjdk-jmods, p-cpe:/a:amazon:linux:java-11-openjdk-jmods-debug, p-cpe:/a:amazon:linux:java-11-openjdk-src, p-cpe:/a:amazon:linux:java-11-openjdk-src-debug, cpe:/o:amazon:linux:2
🌐
AWS re:Post
repost.aws › questions › QUY8xB-CpKRWWmk-eCzpn0TQ › how-to-install-openjdk-11-0-16-version-in-amazon-linux-2
How to install openjdk-11.0.16 version in amazon linux 2 | AWS re:Post
November 23, 2022 - wget https://builds.openlogic.com/downloadJDK/openlogic-openjdk-jre/11.0.16+8/openlogic-openjdk-jre-11.0.16+8-linux-x64.tar.gz mv openlogic-openjdk-jre-11.0.16+8-linux-x64 /usr/jdk-11.0.16 # add this to your /etc/profile export JAVA_HOME=/usr/jdk-11.0.16 export PATH=$PATH:$JAVA_HOME/bin # then,you just source this env source /etc/profile # check the java version [root@ip-172-31-23-10 ~]# java -version openjdk version "11.0.16" 2022-07-19 OpenJDK Runtime Environment OpenLogic-OpenJDK (build 11.0.16+8-adhoc.root.jdk11u) OpenJDK 64-Bit Server VM OpenLogic-OpenJDK (build 11.0.16+8-adhoc.root.jdk11
🌐
Tenable
tenable.com › plugins › nessus › 163358
Amazon Linux 2 : java-11-amazon-corretto (ALAS-2022-1822)<!-- --> | Tenable®
July 21, 2022 - The version of java-11-amazon-corretto installed on the remote host is prior to 11.0.16+8-1. It is, therefore, affected by multiple vulnerabilities as referenced in the ALAS2-2022-1822 advisory. Generated code produced by C1 may leak a package-private class to a class from a different package.