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
Installation instructions for Corretto 25 failing on EC2
centos7 - Is there a way to install OpenJDK Java in Amazon Linux 2023? - Stack Overflow
java-11-openjdk-devel for Amazon Linux 2
java - How do I install JDK 15 on my AWS Linux Ec2 instance? - Stack Overflow
Videos
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've installed (and uninstalled) Corretto 21 easily on my EC2 instance, specifically using "sudo yum install java-21-amazon-corretto-devel" and "sudo yum remove java-21-amazon-corretto-devel" respectively.
However, when I follow the same instructions for Corretto 25 (see Amazon Corretto 25 Installation Instructions for Amazon Linux 2023 - Amazon Corretto 25) it doesn't work:
sudo yum install java-25-amazon-corretto-devel Amazon Linux 2023 Kernel Livepatch repository 42 kB/s | 2.9 kB 00:00 Amazon Linux 2023 Kernel Livepatch repository 217 kB/s | 23 kB 00:00 Last metadata expiration check: 0:00:01 ago on Wed Oct 15 20:33:30 2025. No match for argument: java-25-amazon-corretto-devel Error: Unable to find a match: java-25-amazon-corretto-devel
And the failure is the same for other variants, like "sudo yum install java-25-amazon-corretto".
I've confirmed my EC2 is running Amazon Linux 2023.
Any idea what I'm missing..?
UPDATE: Corretto 25 was released late September, so I just had to update my OS: sudo dnf --releasever=latest update