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)
java-11-openjdk-devel for Amazon Linux 2
How to install openjdk-11.0.16 version in amazon linux 2
Failed to install java in Amazon Linux 2 - Stack Overflow
java - Can't install openjdk-11 with yum in container - Stack Overflow
Videos
Download Java 11 from java.net
wget https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz
Extract it to /usr/local/bin:
sudo tar -xvf openjdk-11+28_linux-x64_bin.tar.gz -C /usr/local/bin
edit /etc/bashrc and add the following to the end of the file:
export PATH=${PATH}:/usr/local/bin/jdk-11/bin
export JAVA_HOME=/usr/local/bin/jdk-11
Run the source command to make sure the changes are reflected.
source /etc/bashrc
Check if Java has been installed
java --version
On Amazon Linux 2023, use:
sudo dnf install java-11-amazon-corretto -y
It seems that the amazon-linux-extras package manager is not installed or not found in your system. Assuming you are using Amazon Linux 2, you can follow these steps to install OpenJDK 11 on your EC2 instance:
Update your system packages:
sudo yum update -y
Install the amazon-linux-extras package manager if it is not available:
sudo yum install -y amazon-linux-extras
Enable and install OpenJDK 11:
sudo amazon-linux-extras enable java-openjdk11
sudo yum clean metadata
sudo yum install -y java-11-openjdk
Verify that Java has been installed successfully:
java -version
If everything went well, you should see the installed OpenJDK 11 version details.
Keep in mind that if you're using a different version of Amazon Linux or another Linux distribution, the steps may vary.
For "Amazon Linux 2003" AMI, you can use the following command:
sudo dnf install java-11-amazon-corretto -y
For "Amazon Linux 2" AMI, use
sudo amazon-linux-extras install java-openjdk11 -y
If you're using Amazon linux 2, Use this
sudo amazon-linux-extras install java-openjdk11