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)
Top answer
1 of 2
1

I am guessing you are using amazon linux ami

sudo yum install java 


then press tab twice it will show you list of available options like below

Then complete the installation with chosen version example

sudo yum install java-11-amazon-corretto-headless.x86_64
2 of 2
-1

The error message Unable to find a match: java-1.8.0-openjdk means that the yum package manager cannot find the java-1.8.0-openjdk package in the repositories. This can happen if the package is not available in the repositories, or if the repositories are not configured correctly.

To fix this error, you can try the following:

  1. Make sure that the repositories are configured correctly. You can do this by running the following command:
sudo yum repolist

This will list all of the repositories that are configured on your EC2 instance. Make sure that the repository that contains the java-1.8.0-openjdk package is listed.

  1. If the repository is listed, try updating the repositories:
sudo yum update

This will update the package manager's knowledge of the repositories.

  1. If the package is still not found, you can try installing it manually. You can download the java-1.8.0-openjdk RPM package from the Oracle website. Once you have downloaded the RPM package, you can install it using the following command:
sudo yum localinstall java-1.8.0-openjdk-*.rpm

Once the java-1.8.0-openjdk package is installed, you should be able to run the java -version command without any errors.

Here are some additional tips for installing Java on EC2:

  • You can also use the Amazon Corretto distribution of OpenJDK, which is available in the Amazon Linux repositories. To install Corretto, run the following command:
sudo yum install java-11-amazon-corretto-11.0.5+10-1.amzn2.x86_64
🌐
Reddit
reddit.com › r/learnjava › installing java11 with yum (on aws ec2 linux instance)
r/learnjava on Reddit: Installing java11 with yum (on AWS EC2 Linux instance)
July 24, 2019 -

I am trying to figure out how to install java11 on EC2

> sudo yum install java-11-openjdk-devel
Loaded plugins: priorities, update-motd, upgrade-helper
1147 packages excluded due to repository priority protections
No package java-11-openjdk-devel available.
Error: Nothing to do

I tried to clean yum

> sudo yum clean all
> sudo yum clean metadata

Still doesn't work. Tried to download it manually:

> sudo wget http://vault.centos.org/7.6.1810/updates/Source/SPackages/java-11-openjdk-11.0.3.7-0.el7_6.src.rpm
> sudo rpm -ihv java-11-openjdk-11.0.3.7-0.el7_6.src.rpm

Still

No package java-11-openjdk-devel available.

What do I need to do?

🌐
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. ... We are already connected to the EC2 instance, let’s run the above command.
🌐
CodingTechRoom
codingtechroom.com › question › how-to-install-java-11-on-aws-ec2-linux-instance
How to Install Java 11 on an AWS EC2 Linux Instance - CodingTechRoom
# Connect to your EC2 instance via SSH ssh -i your-key.pem ec2-user@your-ec2-public-dns # Update the package index (for Debian/Ubuntu) sudo apt update # Install OpenJDK 11 gsudo apt install openjdk-11-jdk -y # Verify the installation java -version · The EC2 instance defaults may not have Java ...
🌐
Medium
codewithmuh.medium.com › install-java-on-the-redhat-linux-ec2-instance-4eb613011044
Install Java on the RedHat Linux EC2 instance | by CodeWithMuh | Medium
November 27, 2022 - ~/.bashrc fi # User specific environment and startup programs JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.17.0.8–2.el9_0.x86_64 PATH=$PATH:$JAVA_HOME:$HOME/bin export PATH · Now exit, by using the ‘exit’, then login to root by · $ exit $ sudo su - now you can confirm the path by running this · $ echo $JAVA_HOME · it will output the latest path. We are done with java. Thanks for reading my Article. Java · Ec2 · Linux ·
🌐
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
Find elsewhere
🌐
CodingTechRoom
codingtechroom.com › question › step-by-step-guide-to-install-java-11-on-an-aws-ec2-linux-instance
CodingTechRoom - Step-by-Step Guide to Install Java 11 on an AWS EC2 Linux Instance
Below is a detailed guide to install Java 11 on two popular distributions: Amazon Linux and Ubuntu. 1. Connect to your EC2 Instance: Start by connecting to your EC2 instance via SSH.
🌐
TecAdmin
tecadmin.net › install-java-on-amazon-linux
How to Install Java (JDK/JRE) on Amazon Linux – TecAdmin
April 26, 2025 - For those using Amazon Linux, a popular choice in cloud environments for its stability and security, installing Java is a critical first step in setting up a development or production environment. 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.
🌐
Reddit
reddit.com › r/javahelp › installing java11 with yum (on aws ec2 linux instance)
r/javahelp on Reddit: Installing java11 with yum (on AWS EC2 Linux instance)
July 24, 2019 -

I am trying to figure out how to install java11 on EC2

> sudo yum install java-11-openjdk-devel
Loaded plugins: priorities, update-motd, upgrade-helper
1147 packages excluded due to repository priority protections
No package java-11-openjdk-devel available.
Error: Nothing to do

I tried to clean yum

> sudo yum clean all
> sudo yum clean metadata

Still doesn't work. Tried to download it manually:

> sudo wget http://vault.centos.org/7.6.1810/updates/Source/SPackages/java-11-openjdk-11.0.3.7-0.el7_6.src.rpm
> sudo rpm -ihv java-11-openjdk-11.0.3.7-0.el7_6.src.rpm

Still

No package java-11-openjdk-devel available.

What do I need to do?

🌐
Eternal Blog
eternalsoftsolutions.com › home › guide on how to install java in aws ec2
How to install Java in AWS EC2: Ultimate Guide
February 11, 2023 - Learn the step-by-step process to install Java on an AWS EC2 instance. This guide will help you set up Java on your EC2 instance quickly and easily.
🌐
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
While it is recommended to use ...atives/java_sdk, /etc/alternatives/java_sdk_11 and /etc/alternatives/java_sdk_11_openjdk for JDK. The paths under /etc/alternatives/ may point to another JDK depending on the packages installed and system configuration....
🌐
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 ...
🌐
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 - jdk 1.8/11 install on an EC2 aws linux In order to install jdk and jps JDK 11 : sudo amazon-linux-extras install java-openjdk11-devel JDK 8 sudo yum install java-1.8.0-openjdk-devel -y switch between …
🌐
Medium
mnzel.medium.com › how-to-install-java-on-your-amazon-ec2-instance-8598aa67a628
How to install Java on your Amazon EC2 instance in 2025? | by Manzeel Uprety | Medium
February 21, 2025 - scp -i "mypemfile.pem" ~/Downloads/jdk-11.0.25_linux-x64_bin.tar.gz ubuntu@ec2-x-xxx-xx-0.ap-south-1.compute.amazonaws.com:/usr/lib/jvm · 2️⃣ Once the upload is complete, reconnect to your EC2 instance and navigate to the jvm directory: ... update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-11.0.25/bin/java" 0 update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk-11.0.25/bin/javac" 0
🌐
LinkedIn
linkedin.com › pulse › how-install-java-your-amazon-ec2-instance-manzeel-uprety-1e
How to install Java on your Amazon EC2 instance?
August 24, 2021 - Now, you need to update the system about the java information (java) and java compile (javac) [ec2-user@ip-xxx-xx-xx-xxxx jvm]$ update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-16.0.2/bin/java" 0 [ec2-user@ip-xxx-xx-xx-xxxx jvm]$ update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk-16.0.2/bin/javac" 0
🌐
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 - Step 8: We have successfully installed Java JDK11 on our EC2 instance, to check if JDK11 is installed or not, verify using the following command. ... In this way, we can install Java JDK 11 on our EC2 instance using EC2 Instance Connect.
🌐
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.jdk11u, mixed mode) I hope this can help you,hava a nice day! ... How can I install a "-generic" Linux kernel version on my EC2 Ubuntu instance rather than the "-aws" version?