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
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)
🌐
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 - As we already saw, you can install openjdk 11 on amazon linux 2 using amazon-linux-extras install java-openjdk11 command.
Discussions

java-11-openjdk-devel for Amazon Linux 2
Does anyone when the java-11-openjdk-devel will be available in the Amazon Linux 2 yum repo? More on repost.aws
🌐 repost.aws
6
0
January 31, 2019
Failed to install java in Amazon Linux 2 - Stack Overflow
I am using sudo amazon-linux-extras install java-openjdk11 this command,but it says sudo: amazon-linux-extras: command not found How I can install java in my ec2 ? I am using sudo amazon-linux-extras More on stackoverflow.com
🌐 stackoverflow.com
java - Can't install openjdk-11 with yum in container - Stack Overflow
I am trying to install openjdk-11 inside a container (lambci/lambda:build-python3.6) Multiple sources claim you can install openjdk 11 by running: yum update yum install java-11-openjdk-devel How... More on stackoverflow.com
🌐 stackoverflow.com
How to install openjdk-11.0.16 version in amazon linux 2
I have to install a specific version of openjdk i.e, openjdk-11.0.16 in amazon linux 2. I don't want to install coretto11. we can install using amazon-linux-extras install java-openjdk11, but this... More on repost.aws
🌐 repost.aws
1
0
November 23, 2022
🌐
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 - sudo amazon-linux-extras install java-openjdk11 · Type "Y" for install packages · Wait until all packages finished install · Command: java -version · Subscribe · For further actions, you may consider blocking this person and/or reporting ...
🌐
DevCoops
devcoops.com › install-java-11-on-amazon-linux-2
Install Java 11 on Amazon Linux 2 | DevCoops
October 8, 2022 - sudo amazon-linux-extras install java-openjdk11 · Step 2. Verify the installation. java -version · Step 3. If you have multi-java environment, and you want to switch the java version, run: alternatives --config java · Feel free to leave a comment below and if you find this tutorial useful, ...
🌐
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 ...
🌐
GitHub
github.com › mothkoor › application-setup-aws
GitHub - mothkoor/application-setup-aws: Instructions for setting up your web application on Amazon Web Services ( Steps include JAVA, Tomcat & MYSQL Setup) · GitHub
>>sudo amazon-linux-extras install java-openjdk11 · • Check whether java is installed by typing · >> java -version · • Set JAVA_HOME by adding below lines in /etc/profile · export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.5.10-0.a...
Author   mothkoor
🌐
Medium
medium.com › @kildongp › jdk-1-8-11-install-on-an-ec2-aws-linux-f98dc1555f0f
jdk 1.8/11 install on an EC2 aws linux - Kildongp - Medium
January 24, 2024 - sudo amazon-linux-extras install java-openjdk11-devel · JDK 8 · sudo yum install java-1.8.0-openjdk-devel -y · switch between java versions ·
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › installation guide › how-to-install-java-jdk11-on-aws-ec2
How to Install Java JDK11 on AWS EC2? - GeeksforGeeks
July 23, 2025 - //if the above code doesn't work try this --> sudo amazon-linux-extras install java-openjdk11 · Step 7: Wait for the process to end. Step 8: We have successfully installed Java JDK11 on our EC2 instance, to check if JDK11 is installed or not, ...
🌐
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. Before proceeding, ensure you meet the following prerequisites: You have an instance of Amazon Linux 2 running. You have access to the terminal or command line. You have sudo privileges or access to the root user.
🌐
SearchBlox
developer.searchblox.com › v9.2 › docs › installing-on-amazon-linux
Installing on Amazon Linux 2 - Architecture
Install OpenJDK 11 by running the following command: amazon-linux-extras install -y java-openjdk11 Install wget by running the following command: yum install wget Verify the installation by running the following command: java -version Increa...
🌐
iHusyn
ihusyn.wordpress.com › 2019 › 11 › 01 › how-to-install-java-11-on-amazon-linux
How to install Java 11 on Amazon Linux | iHusyn
February 21, 2024 - I have to install SonarQube 8 on an EC2 instance with Amazon Linux 2. For SonarQube version 7.9+ the requirement is to have Java 11 JDK on the system. To install Java11 JDK on Amazon Linux there is no direct way from yum package manager. You have to download it manually and install it from…
🌐
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 - I have to install a specific version of openjdk i.e, openjdk-11.0.16 in amazon linux 2. I don't want to install coretto11. we can install using amazon-linux-extras install java-openjdk11, but this approach always installs the latest version ...
🌐
javathinking
javathinking.com › blog › aws-how-to-install-java11-on-an-ec2-linux-machine
How to Install Java 11 on AWS EC2 Linux Machine: Fixing wget 404 Error & 'amazon-linux-extras Not Found' Issues — javathinking.com
Use dnf directly: ... Amazon Linux 1’s default repos don’t include Java 11. Use the IUS Community repo (for up-to-date packages): sudo yum install https://centos7.iuscommunity.org/ius-release.rpm -y sudo yum install java-11-openjdk-devel -y
🌐
Stack Overflow
stackoverflow.com › questions › 74333260 › usr-lib-jvm-java-11-openjdk-11-0-16-0-8-1-amzn2-0-1-x86-64-doesn-t-look-like-a
jenkins - /usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64 doesn’t look like a JDK directory - Stack Overflow
===Install Java===== sudo amazon-linux-extras sudo amazon-linux-extras install java-openjdk11 -y java --version sudo su - echo "export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.16.0.8-1.amzn2.0.1.x86_64" >> .bash_profile echo "export ...
🌐
How2Shout
how2shout.com › home › how to install java 8/11 on amazon linux 2023
How to install Java 8/11 on Amazon Linux 2023 - LinuxShout
June 24, 2023 - Learn commands available to install Java 11 or 8 on Amazon Linux 2023 for production or business applications in your cloud infrastructure