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
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
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)
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
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:
- 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.
- If the repository is listed, try updating the repositories:
sudo yum update
This will update the package manager's knowledge of the repositories.
- If the package is still not found, you can try installing it manually. You can download the
java-1.8.0-openjdkRPM 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
Videos
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?
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?
check Java current version
java -version
install Java 1.8
sudo yum install java-1.8.0
change the Java version
sudo alternatives --config java
Java 8 may not be available out-of-the-box on the AMI that you are looking for. However, you can always install it once the instance is created.
e.g. Check this post which explains how to install java 8 on Ubuntu OR check this post which explains how to install Java 8 on RHEL/Fedora/CentOS.