Here we go through the commands available to install Java 11 or 8 on Amazon Linux 2023 for production or business applications in your cloud infrastructure. Java is available through the Amazon 2023 repositories as Corretto.
But, what is Amazon Corretto?
Amazon Corretto is a distribution of the Open Java Development Kit (OpenJDK) developed and maintained by the Amazon Web Services (AWS) Team. This is designed to use on the AWS Linux platform to get a number of benefits when running Java applications. Here are some of the reasons why you should choose Java Corretto to develop or run applications on Amazon:
- Amazon Corretto is meant to provide high performance and stability by providing bug fixes, and security patches.
- Long-Term Support (LTS) for major Java versions typically for at least 8 years from the initial release.
- Corretto is designed with security in mind.
- It undergoes rigorous testing and verification processes to ensure compatibility with popular Java applications, libraries, and frameworks.
- Free of charge
- Supported by a large and active community of Java developers and AWS users.
Step 1: Update Your System:
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.
sudo dnf update
Step 2: Install Corretto or Java on Amazon 2023
Unlike Amazon Linux 2, AWS’s Corretto is a production-ready distribution of OpenJDK available through the default system repository of Amazon Linux 2023. So, we can install Java without adding any extra repository.
Just in your command terminal type:
For Java 8:
To get JRE
sudo dnf install java-1.8.0-amazon-corretto
To get JDK
sudo dnf install java-1.8.0-amazon-corretto-devel
For Java 11:
For JRE 11
sudo dnf install java-11-amazon-corretto
For JDK 11
sudo dnf install java-11-amazon-corretto-devel
Step 3: Check installed JAVA Version
By following the above commands you will definitely have the Java version you want to install on your Amazon Linux 2023. To confirm that we can use the given command.
Step 4: How to Switch between Java versions
If you have multiple Java versions installed on your Amazon Linxu 2023 let’s say you have both Java 8 and Java 11 on your system. Now, to switch between and make any one of them the default Java version of your system, we can use the “alternative –config” command.
alternatives --config java
Type the Selection number of the Java you want to set as default system one and hit the Enter key.