Learn how to install Java on Amazon Linux 2 instance in this article. This tutorial will help you to install Java on both Amazon Lightsail and EC2 instance.
Steps to install Java on Amazon Linux 2
Before starting Java installation on Amazon Linux, we want to provide system information.
System Information : In this tutorial we are using Amazon Linux 2 as an operating system. We will use Corretto 11 to install Java on Amazon Linux 2 instance.
So let us see a step by step guide to install Java on Amazon Linux 2.
We will use yum command to install Corretto and further Java. In case yum command is not working, you can install yum packages for Amazon Linux.
Once you are ready with yum packages. Firstly, install Corretto using the yum Package Manager on Amazon Linux 2.
Moreover, there are 2 versions of Amazon Corretto 11. One is headless and another one is full.
However, Let us see how to install both the versions one by one. Moreover, we suggest either use headless or full version of Amazon Corretto.
Option 1: Install headless Amazon Corretto 11:
sudo yum install java-11-amazon-corretto-headless
Option 2: Install the full Amazon Corretto 11:
sudo yum install java-11-amazon-corretto
Once the installation is successful, the installation location is :
Now it’s time to verify your installation :
In order to verify the installation, run java -version in a console.
If the version string doesn’t mention Corretto, run the following command to change the default java provider.
sudo alternatives --config java
In case you have changed you have changed your mind and want to uninstall Corretto. In this case, Please run this command to uninstall Corretto.
Command to uninstall headless Corretto :
sudo yum remove java-11-amazon-corretto-headless
Command to uninstall full Corretto :
sudo yum remove java-11-amazon-corretto
What is Corretto 11 ?
In this tutorial, we used Corretto 11 to install Java on Amazon Linux 2. Amazon Corretto is nothing but an updated version of OpenJDK by Amazon. Hence, the installation is similar to OpenJDK.
To clarify, Amazon Corretto is a distribution released by Amazon by fixing some patches in OpenJDK. As you know OpenJDK is an open source. Amazon started contributing to OpenJDK in 2017.
Basically, Amazon has fixed the security patches, scalability in OpenJDK. Afterwards, Amazon has released Corretto.
Corretto is released under GPL. Amazon is committed to support it. Moreover, Amazon provides quarterly releases to Corretto.
Since Corretto uses OpenJDK internally and launched with fix patches, we suggest newbies to use it. Because you will get all the advantages of OpenJDK along with the benefits of security and scalability.
Apart from that, Corretto is available on other operating systems also. For example it is available for Mac OS, Windows etc.
In order to know more about Corretto, please read our article all about Corretto features and benefits.
References to install Java on Amazon Linux 2 Lightsail and EC2
We refer to AWS documentation for this Java installation article. We simplified the technical terms for you. Please follow this link for further learning – AWS official documentation for Corretto 11 installation on Amazon Linux 2.
Finally, you learn how to install Java on Amazon Linux 2. You also learnt how to uninstall Java from Amazon Linux 2.
Further, Please read our article on Amazon Lightsail.