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
Answer from JustTry on Stack Overflow
🌐
Medium
medium.com › @samb333 › installing-java-on-aws-ubuntu-ec2-instance-4499c1aa6f4c
Installing Java on AWS Ubuntu ec2 instance | by fisheye | Medium
January 4, 2024 - curl -O https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html#license-lightbox ... The Oracle Sun downloads have license agreemtent modal and curl will fail. So logon to Oracle page and download your version tar file (we need jdk1.8 so we got the same) ... We are on ubuntu we do not have deb we have rpm archive.
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
🌐
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 - If you’re setting up Java on an AWS EC2 instance, this guide is for you. Let’s get started! 1️⃣ Login to your AWS Console and navigate to the EC2 Dashboard. 2️⃣ Click Launch Instance and configure the instance as per your requirements.
🌐
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 - Configure Security Group (Please make sure you have SSH port 22 open in the security group) & click on Next ... If you are fairly new to AWS environment, you should know “how to launch an EC2 instance in AWS”. ... $ chmod 400 new_keypair.pem #if you have a new key pair $ ssh -i new_keypair.pem ubuntu@public_ip_address · By update and upgrading the server you will get the latest packages and versions to install in the server. ... You may need the Java Development Kit (JDK) in addition to the JRE in order to compile and run some specific Java-based software.
🌐
DEV Community
dev.to › kedster › set-up-java-dev-environment-on-ec2-ubuntu-free-tier-45ok
Set Up Java Dev Environment on EC2 (Ubuntu): Free Tier - DEV Community
May 3, 2025 - 1. Launch EC2 Instance (Ubuntu ... your-key.pem ubuntu@your-ec2-public-dns · Install Java 17 (Temurin) sudo apt update sudo apt install -y wget gnupg curl ·...
Find elsewhere
🌐
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 3: Connect to your EC2 Instance by clicking on Connect Button. Step 4: A prompt will pop up after connecting. Step 5: At first check, if Java JDK is already installed or not.
🌐
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'.
🌐
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 - Launch Red-hat Linux EC2 instance · SSH into your instance with Terminal to connect with the instance · Run this command to become a Root User · $ sudo su - #To become root user · 4. Then Update the machine with this command · $ yum updat · 5. Now check the java version, Linux machine comes with java installed.
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 $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)
🌐
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 - On the Nano editor, add the following path. PATH= “/usr/lib/jvm/jdk-jdk-16.0.2/bin” JAVA_HOME= “/usr/lib/jvm/jdk-jdk-16.0.2” · Save the changes using, ctrl-x and press yes and hit enter. 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
🌐
LearnAWS
learnaws.io › blog › java-ec2-deployment
How to deploy Java on Amazon EC2 (Spring Boot edition)
June 21, 2024 - [ec2-user@ip-172-31-19-82 ~]$ sudo yum install java-17-amazon-corretto-headless Last metadata expiration check: 1 day, 17:42:09 ago on Tue Jun 18 04:50:04 2024. Dependencies resolved.
🌐
Bhargav Amin
bhargavamin.com › home › setting up java environment variable on amazon linux – ec2
Setting up JAVA environment variable on Amazon Linux - EC2 - Bhargav Amin - Blog
August 28, 2020 - Steps to set JAVA enviroment variable on Amazon Linux in 4 simple steps. (Updated 14th Jan 2020) Step 1: Check & install correct JAVA version (Optional) Check if JAVA exists on your device by running : java --version The latest version of JAVA OpenJDK is 1.8, by default Amazon Linux AMI may or may not a JAVA installation so you would directly want to install/upgrade it use below command : You can list all the available OpenJDK versions using : sudo yum list | grep openjdk You can select the desired version from the output list and install it sudo yum install java-1.8.0-openjdk.x86_64 If you already have JAVA installed you can change/check the JAVA version using below command.
🌐
Medium
medium.com › @mertcal › easily-install-oracle-jdk8-on-your-ec2-instance-9317644a42fa
Easily install Oracle JDK8 on your EC2 instance | by Mert Çalışkan | Medium
July 27, 2015 - sudo wget --no-cookies --no-check-certificate --header “Cookie: gpw_e24=http://www.oracle.com/; oraclelicense=accept-securebackup-cookie” “https://download.oracle.com/otn-pub/java/jdk/8u51-b16/jdk-8u51-linux-x64.rpm" Do replace quotation marks after copying the command from here. medium.com replaces them with a different version. ... After the installation you should be seeing the exact details given as follows by executing java -version.
🌐
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.
🌐
Medium
medium.com › @sambhaji2134 › install-latest-oracle-jdk-on-linux-ec2-instance-78eda5d62cc6
Install Latest Oracle JDK On Linux EC2 Instance | by Sambhaji Karad | Medium
October 1, 2019 - Install Latest Oracle JDK On Linux EC2 Instance We will explore the procedure to install latest java 8 version ie JDK 8u121 on the EC2 Linux instance which comes with centOS as its default operating …
🌐
Medium
medium.com › @migarathiranagama › how-to-install-java-in-an-ec2-instance-cc700dab972
How To Install Java In An EC2 Instance | by migara thiranagama | Medium
December 13, 2021 - How To Install Java In An EC2 Instance. there are some linux commands that you need to know if you are willing to install java into your running ec2 instance.