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)
🌐
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 ...
Discussions

java-11-openjdk-devel for Amazon Linux 2
To install the java-11-openjdk packages on an Amazon Linux 2 instance run: ... Thanks for your request. -Heath ... Any word on when this will be available on beanstalk? As of now I only see JDK 7 and 8 as options when creating new Java environments. ... Hello, I run following and got error. ... Could not retrieve mirrorlist http://amazonlinux.ap-east-1.amazonaws.com/2/extras/java-openjdk11... More on repost.aws
🌐 repost.aws
6
0
January 31, 2019
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
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
🌐
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.
🌐
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 ...
🌐
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, ...
🌐
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
🌐
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
🌐
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, ...
🌐
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...
🌐
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 ...
🌐
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 ·
🌐
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
🌐
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 - sudo curl -o java11.rpm https://d3pxv6yz143wms.cloudfront.net/11.0.5.10.1/java-11-amazon-corretto-devel-11.0.5.10-1.x86_64.rpm · From the same directory execute the following command to install java 11
🌐
LinuxShout
linux.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 - Unlike Amazon Linux 2, AWS’s Corretto is a production-ready distribution of OpenJDK available through the default system repository of Amazon Linux 2023. So, we can install Java without adding any extra repository.
🌐
GitHub
gist.github.com › sampathshivakumar › 54449ea95540ad0fd0f0cf44beb54ff9
Jenkins Installation on Amazon-Linux-2.md · GitHub
# Become a root sudo su - # Jenkins repo is added to yum.repos.d sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo # Import key from Jenkins sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key # Install Java-11 amazon-linux-extras install java-openjdk11 -y # Install Jenkins yum install jenkins -y ·