How to Install Java 8/11/17 on Amazon Linux 2023 Instance
Dear Reader, I hope you are doing amazing today. In my last few posts, I have shared with you how to install Jenkins, Git, Ansible, Nginx, Apache, Docker, Java, Python, PHP 8.1, MySQL 8 etc. on Amazon Linux 2023 or AL2023 EC2 Instance.
In this post, we’ll talk about how to install Java 8, Java 11 and Java 17 on Amazon Linux 2023 EC2 Instance in a step-by-step manner.
So are you ready?
Alright, let’s start.
Background on Java and Amazon Linux 2023
Amazon Linux 2023: Amazon Linux 2023 or AL2023 is the next-generation Amazon Linux AMI provided by AWS. It leverages the latest Linux innovations to deliver high-performance and stable Linux systems.
Java: Java is one of the most popular languages out there. As a result, many of you asked how to install Java on Amazon Linux 2023 EC2 Instance. And that’s why I am here with this post.
I see people asking for Java 8, Java 11 and Java 17 most of the time. To be honest these are the versions that are most used. So I will cover all three of them in this post.
Don’t want to miss any posts from us? join us on our Facebook group, and follow us on Facebook, Twitter, LinkedIn, and Instagram. You can also subscribe to our newsletter below to not miss any updates from us.
Prerequisite for Installing Java on Amazon Linux 2023
Before you install Java in your Amazon Linux 2023 or AL2023 EC2 instance, You need to have one instance up and running.
I have got you covered in one of my previous post–
Additionally, if you don’t have a free tier account, check out how to set up a free tier AWS account in right way. Having said that, don’t forget to set up a cost budget to avoid last-minute billing shocks.
Steps to Install Java 8/11/17 on Amazon Linux 2023 Instance
- Connect to Your Amazon Linux 2023 Instance
- Run System Update
- Search for Available Java Package
- Install Java on Your AL2023
- Verify Java Installation
- Make javac Work
Step 1: Connect to Your Amazon Linux 2023 Instance
We already have an up-and-running Amazon Linux 2023 EC2 instance. Let’s connect to it to be able to run commands so that we can install Java on it.
In case you don’t already have an EC2 running, create one using one of my previous tutorials.
In order to connect to your instance from the local system, you can use the below SSH command and replace the public IP and path of the .pem file as per your need.
ssh -i /path/my-key-pair.pem ec2-user@instance-public-ip
However, I prefer the EC2 instance connect option which is very straightforward. Moreover, it allows me to connect to my instance from the browser itself.
All you need is, to select your EC2 instance and click Connect.
Once you click connect, the EC2 Instance Connect option opens by default. Verify that ec2-user is showing in the user-name field and click connect again.
Within seconds a new browser window opens and you are connected to your instance as shown below.
Step 2: Run System Update
Before installing any software on your system, you should update your system packages to the latest.
sudo dnf update
Type sudo dnf update and hit enter.
Updates are installed if any.
Step 3: Search for Available Java Package
You can check out Amazon Linux 2023 package repo list for the latest packages available in Al2023. At the time of writing this, I found you will find these-
If you are wondering about amazon-corretto in the package name- Amazon Corretto is a no-cost, multiplatform, production-ready distribution of the OpenJDK or Open Java Development Kit. Corretto comes with long-term support that will include performance enhancements and security fixes. It is backed by Amazon and provides long-term support.
Our explanation means then –
- java-1.8.0-amazon-corretto -> Open JDK 8
- java-11-amazon-corretto -> OpenJDK 11
- java-17-amazon-corretto -> OpenJDK 17
This means you are ideally installing OpenJDK 8/11/17 using the above package.
You can also check this out using the command-
sudo dnf list | grep java-
In the beginning, I searched just by grep java but it was returning too many results. Therefore, to narrow it down I searched everything that matches java-
And you can notice all the corretto packages. Let’s move ahead to install Java.
Step 4: Install Java 8/11/17 on Amazon Linux 2023
You can tweak the command to install Java on Amazon Linux 2023 based on which version of the OpenJDK you want to install on your Amazon Linux 2023 instance.
Also please note that the package java-17-amazon-corretto only installed Java runtime and not JDK and development-related tools. That’s okay if you are installing Java for a server however if you are installing for a dev machine, install java-17-amazon-corretto-devel package.
4.1: Install Java 8 on Amazon Linux 2023
Only Java Runtime(For servers)
sudo dnf install java-1.8.0-amazon-corretto -y
4.2: Install Java 11 on Amazon Linux 2023
sudo dnf install java-11-amazon-corretto -y
4.3: Install Java 17 on Amazon Linux 2023
sudo dnf install java-17-amazon-corretto -y
Step 5: Verify Java Installation
After installing Java above by using the command sudo dnf install java-1.8.0-amazon-corretto -y, only java runtime is installed. Which is fine if you want to use the system as a Java server.
However, if you are setting up a Java development environment on your system, you need dev tools and a JDK feature. Let’s find out how to do that in the next section.
Step 6: Make javac Work
To make javac and other development-related tools/features work, you need to install the devel package.
for example for Java 8 – here is how you installed the development package.
sudo dnf install java-1.8.0-amazon-corretto-devel
Please note that after installing devel package, you don’t need to install the Java runtime separately. Because the devel package installs the runtime as well.
This means as soon as you install Devel, both Java and javac will work fine As JDK and JRE both are installed.
Similarly, you can install Java 11 and Java 17 dev packages using the below commands-
sudo dnf install java-11-amazon-corretto-devel -y
sudo dnf install java-17-amazon-corretto-devel -y
I have added -y as well so that it doesn’t prompt you if you want to install it or not. As I stated earlier, after running one of the commands from above, this is what you see in the installed-
As you might have noticed from the above screenshot, A headless version of corretto is installed as well with devel which is nothing but a light Java runtime containing only what’s necessary.
Conclusion
In this how-to guide, you learn how to install Java 8/11/17 on Amazon Linux 2023 Instance. We learned how to find a Java package on Amazon Linux 2023 or AL2023. And then we installed it on our EC2 instance running AL2023.
We also confirmed that java and javac both work after installation to confirm the development environment setup.
Also Read: How to Install Docker on Amazon Linux 2023
Were you able to install Java 8/11/17 on Amazon Linux 2023 using this tutorial? Let me know in the comment section.
Enjoyed the content?
Subscribe to our newsletter below to get awesome AWS learning materials delivered straight to your inbox.
Don’t forget to motivate us-
2 thoughts on “How to Install Java 8/11/17 on Amazon Linux 2023 Instance”
Great guide! This article provides clear and helpful steps on how to install Java 8, 11, and 17 on an Amazon Linux 2023 instance, making it easier for users to set up their environments.