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
🌐
AWS
docs.aws.amazon.com › corretto › corretto 17 user guide › amazon corretto 17 guide for linux › amazon corretto 17 installation instructions for amazon linux 2 and amazon linux 2023
Amazon Corretto 17 Installation Instructions for Amazon Linux 2 and Amazon Linux 2023 - Amazon Corretto 17
Option 1: Install the headless Amazon Corretto 17: ... While it is recommended to use /usr/lib/jvm/java-17-amazon-corretto.<cpu_arch> location, installation may also add alternative links making installation location accessible via /etc/alternatives/jre, /etc/alternatives/jre_17 and ...
🌐
DZone
dzone.com › coding › tools › installing java 8 on aws ec2 amazon linux instance
Installing Java 8 on AWS EC2 Amazon Linux Instance
January 30, 2018 - I am not going to waste your time and will instead jump directly towards the commands that you have to execute to install JDK 8 on your new instance. Before we start, please ensure you have the administrative privileges. OK. So, you have to execute the following commands as mentioned below. $ cd /opt $ sudo wget --no-cookies --no-check-certificate --header "Cookie: ://www.oracle.com/; -securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-x64.tar.gz $ sudo tar xzf jdk-8u151-linux-x64.tar.gz $ cd jdk1.8.0_151/ $ sudo alternatives --install /usr/bin/java java /opt/jdk1.8.0_151/bin/java 2 $ sudo alternatives --config java There are 2 programs which provide 'java'.
Discussions

java - AWS - How to install java11 on an EC2 Linux machine? - Stack Overflow
I tried this Downloading Java JDK on Linux via wget is shown license page instead but I keep getting a 404 error. This command "sudo amazon-linux-extras install java-openjdk11" just states that More on stackoverflow.com
🌐 stackoverflow.com
To install Java 8 on Amazon EC2 Linux using Ansible Playbook
Update the Package Name: The package name might be different based on the distribution you are using. If you are using Amazon Linux 2, the correct package name might be java-1.8.0-openjdk-devel. Update the playbook accordingly: - name: Install Java. More on repost.aws
🌐 repost.aws
2
0
August 7, 2023
amazon web services - Java 8 application on EC2 - Stack Overflow
Run "tar zxvf jre-8uversion-li.../8/docs/technotes/guides/install/linux_jre.html#CFHBHAGI ... This question is old but this may help with Java 11. If anybody is interested in installing Java JDK 11, I run ... in my EC2 instance with Amazon Linux.... More on stackoverflow.com
🌐 stackoverflow.com
Amazon linux 2 and java
/var/lib somewhere? More on reddit.com
🌐 r/aws
6
3
February 24, 2022
🌐
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.
🌐
AWS
docs.aws.amazon.com › corretto › corretto 8 user guide › amazon corretto 8 guide for linux › amazon corretto 8 installation instructions for amazon linux 2 and amazon linux 2023
Amazon Corretto 8 Installation Instructions for Amazon Linux 2 and Amazon Linux 2023 - Amazon Corretto 8
Enable the yum repository in Amazon ... Amazon Linux 2022 and later. ... You can install Amazon Corretto 8 as either the runtime environment (JRE) or the full development environment (JDK). The development environment includes the runtime environment. Install Amazon Corretto 8 as JRE. ... Install Amazon Corretto 8 as JDK. ... While it is recommended to use /usr/lib/jvm/java-1.8.0-ama...
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)
🌐
AWS
docs.aws.amazon.com › amazon linux › user guide › getting started with programming runtimes on al2023 › java in al2023
Java in AL2023 - Amazon Linux 2023
May 22, 2026 - AL2023 provides several versions of Amazon Corretto to support Java based workloads. All Java based packages included in AL2023 are built with Amazon Corretto 17 .
🌐
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 - Access your Amazon Linux 2023 command terminal using SSH and then execute the system update command. It will install the latest available updates, if any, plus rebuild the DFN package index cache.
Find elsewhere
🌐
DevelopnSolve
developnsolve.com › installing-java-on-amazon-linux
Installing Java on Amazon Linux - Develop and Solve
January 13, 2024 - Amazon Linux utilizes RPM Package Manager (YUM) to install and manage software packages. To get Java on Amazon Linux, you can use YUM to download and set up a Java environment.
🌐
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
Option 1: Install the headless Amazon Corretto 11: ... While it is recommended to use /usr/lib/jvm/java-11-amazon-corretto.<cpu_arch> location, installation may also add alternative links making installation location accessible via /etc/alternatives/jre, /etc/alternatives/jre_11 and ...
🌐
SearchBlox
developer.searchblox.com › docs › installing-on-amazon-linux
Installing on Amazon Linux 2 - Architecture - SearchBlox
Amazon users can go with Amazon Linux 2023 vs Amazon Linux 2. Recommended EC2 instance type is g6.xlarge . Install OpenJDK 25 by running the following command: sudo yum install java-25-amazon-corretto-devel java -version
🌐
AWS
docs.aws.amazon.com › corretto › corretto 21 user guide › amazon corretto 21 guide for linux › amazon corretto 21 installation instructions for amazon linux 2023
Amazon Corretto 21 Installation Instructions for Amazon Linux 2023 - Amazon Corretto 21
Option 1: Install the headless Amazon Corretto 21: ... While it is recommended to use /usr/lib/jvm/java-21-amazon-corretto.<cpu_arch> location, installation may also add alternative links making installation location accessible via /etc/alternatives/jre, /etc/alternatives/jre_21 and ...
🌐
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 ...
🌐
GitHub
gist.github.com › diegopacheco › 6d69e0cfaf13d4351cfa700bb4af8172
How to Install Java 8 in CentOS / Amazon Linux? · GitHub
# Remove java 7 sudo yum remove -y java # Install basic packages sudo yum install -y git # Download and install java 8 wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http://www.oracle.com/; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz" tar -xzvf jdk-8u131-linux-x64.tar.gz rm -rf jdk-8u131-linux-x64.tar.gz # Configure JAVA_HOME sudo vim ~/.bashrc
🌐
AWS
docs.aws.amazon.com › amazon linux › user guide › getting started with programming runtimes › java in al2
Java in AL2 - Amazon Linux 2
AL2 provides several versions of Amazon Corretto to support Java based workloads, as well as some OpenJDK versions. We recommend that you migrate to Amazon Corretto in preparation for migrating to AL2023.
🌐
AWS re:Post
repost.aws › questions › QUz_J0wOaQSbacKNlQIp0d7A › to-install-java-8-on-amazon-ec2-linux-using-ansible-playbook
To install Java 8 on Amazon EC2 Linux using Ansible Playbook | AWS re:Post
August 7, 2023 - pre_tasks: - name: Enable amzn2-core repository command: amazon-linux-extras enable java-openjdk11 when: ansible_distribution == "Amazon" and ansible_distribution_major_version == "2" - name: Update yum cache if needed. yum: update_cache: true · Consider Using the package Module: Instead of using the yum module, you can use the package module, which is more abstract and works with different package managers. This might help if there's something specific to the yum module causing the issue: - name: Install Java.
🌐
Awswithatiq
awswithatiq.com › how-to-install-java-on-amazon-linux-2023
How to Install Java on Amazon Linux 2023 – AWS with Atiq
This command will download and install the Java Development Kit (JDK) version 1.8 on your Amazon Linux instance.
🌐
ComputingForGeeks
computingforgeeks.com › home › install java 21 (openjdk 21) on amazon linux 2023
Install Java 21 (OpenJDK 21) on Amazon Linux 2023 [Guide]
March 16, 2026 - Learn how to java 21 (OpenJDK 21) on Amazon Linux 2023. Complete guide with commands, configuration, and troubleshooting tips.
🌐
AWS
docs.aws.amazon.com › corretto › corretto 25 user guide › amazon corretto 25 guide for linux › amazon corretto 25 installation instructions for debian-based, rpm-based and alpine linux distributions
Amazon Corretto 25 Installation Instructions for Debian-Based, RPM-Based and Alpine Linux Distributions - Amazon Corretto 25
Download the Linux .rpm file from the Downloads page. Install the downloaded .rpm file using yum localinstall. For example install x86_64 rpm using the following command: sudo yum localinstall java-25-amazon-corretto-devel-25.0.3.9-1.x86_64.rpm
🌐
AWS
docs.aws.amazon.com › corretto › corretto 21 user guide › amazon corretto 21 guide for linux › amazon corretto 21 installation instructions for debian-based, rpm-based and alpine linux distributions
Amazon Corretto 21 Installation Instructions for Debian-Based, RPM-Based and Alpine Linux Distributions - Amazon Corretto 21
Download the Linux .rpm file from the Downloads page. Install the downloaded .rpm file using yum localinstall. For example install x86_64 rpm using the following command: sudo yum localinstall java-21-amazon-corretto-devel-21.0.11.10-1.x86_64.rpm