How To Install Amazon Corretto 8 on Ubuntu 20.04
Categories:
Introduction
In this tutorial we learn how to install Amazon Corretto 8 on Ubuntu 20.04. Amazon Corretto is a no-cost, multiplatform, production-ready distribution of the Open Java Development Kit (OpenJDK).
It comes with long-term support that includes performance enhancements and security fixes. Corretto is certified as compatible with the Java SE standard and is used internally at Amazon for many production services.
Corretto available for Java 8 and Java 11. In this tutorial we learn how to setup Java 8 From Amazon Corretto 8.
Update Apt Package Index
First of all update apt package index using the command below.
sudo apt-get update
or we can also use apt command below.
sudo apt update
Install Amazon Corretto 8 on Ubuntu 20.04 From Repository
Add Amazon Corretto 8 Public Key
First, we will add Amazon Corretto public key to our system so apt can verify the packages that it download is not corrupt or broken.
wget -O- https://apt.corretto.aws/corretto.key | sudo apt-key add -
Add Amazon Corretto Repository Configuration
Run the command below to add Amazon Corretto Repository configuration.
echo 'deb https://apt.corretto.aws stable main' | sudo tee /etc/apt/sources.list.d/corretto.list
Update apt metadata database.
sudo apt-get update;
Install Amazon Corretto 8 using command below
sudo apt-get install -y java-1.8.0-amazon-corretto-jdk
Compile and Run Java Application Using Amazon Corretto 8
In this section we will create a simple Java application, compile and run using Amazon Corretto 8 javac
and java
application.
First, create new file named HelloHowtoDojo.java
with contents below
class HelloHowtoDojo {
public static void main(String[] args) {
String java_class_path = System.getProperty("java.class.path");
String java_home = System.getProperty("java.home");
String java_vendor = System.getProperty("java.vendor");
String java_vendor_url = System.getProperty("java.vendor.url");
String java_version = System.getProperty("java.version");
String os_arch = System.getProperty("os.arch");
String os_name = System.getProperty("os.name");
String os_version = System.getProperty("os.version");
String user_dir = System.getProperty("user.dir");
String user_home = System.getProperty("user.home");
String user_name = System.getProperty("user.name");
System.out.println("Hello howtodojo|");
System.out.println("Java Version :" + java_version);
}
}
Second, compile the source code using command below.
javac HelloHowtoDojo.java
Third, let’s run the application that we just create and compile using Amazon Corretto 8.
$ java HelloHowtoDojo
Hello howtodojo|
Java Class Path : .
Java Home : /usr/lib/jvm/java-1.8.0-amazon-corretto/jre
Java Vendor : Amazon.com Inc.
Java Vendor URL : https://aws.amazon.com/corretto/
Java Version : 1.8.0_262
OS Architecture : amd64
OS Name : Linux
OS Version : 4.4.0-185-generic
User Directory : /home/vagrant
User Home : /home/vagrant
User Name : vagrant
Summary
In this tutorial we learn how to install Amazon Corretto 8 on Ubuntu 20.04. We also learn to create a simple “Hello howtodojo!” program, compile it using javac
and run it using java
that Amazon Corretto provides. Until next time.