How To Install Amazon Corretto 16 on Ubuntu 20.04

Learn how to install Amazon Corretto 16 on Ubuntu 20.04. a no-cost, multiplatform, production-ready distribution of the OpenJDK.

Introduction

In this tutorial we learn how to install Amazon Corretto 16 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 also available for Java 8, Java 11, and Java 15. In this tutorial we learn how to setup Java 16 From Amazon Corretto 16.

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 16 on Ubuntu 20.04 From Repository

Add Amazon Corretto 16 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 16 using command below

sudo apt-get install java-16-amazon-corretto-jdk

Compile and Run Java Application Using Amazon Corretto 16

In this section we will create a simple Java application, compile and run using Amazon Corretto 16 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 Class Path :"  + java_class_path);
      System.out.println("Java Home :"  + java_home);
      System.out.println("Java Vendor :"  + java_vendor);
      System.out.println("Java Vendor URL :"  + java_vendor_url);
      System.out.println("Java Version :"  + java_version);
      System.out.println("OS Architecture :"  + os_arch);
      System.out.println("OS Name :"  + os_name);
      System.out.println("OS Version :"  + os_version);
      System.out.println("User Dir :"  + user_dir);
      System.out.println("User Home :"  + user_home);
      System.out.println("User Name :"  + user_name);
    }
}

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 16.

$ java HelloHowtoDojo
Hello howtodojo!
Java Class Path :.
Java Home :/usr/lib/jvm/java-16-amazon-corretto
Java Vendor :Amazon.com Inc.
Java Vendor URL :https://aws.amazon.com/corretto/
Java Version :16.0.2
OS Architecture :amd64
OS Name :Linux
OS Version :4.16.0-135-generic
User Dir :/home/howtodojo
User Home :/home/howtodojo
User Name :howtodojo

Summary

In this tutorial we learn how to install Amazon Corretto 16 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.