Installing OpenJDK on Ubuntu 18.04

January 04, 2020 No comments Ubuntu OpenJDK8 Install Ubuntu 18.04

1. Introduction

Java is one of the most popular object-oriented programming languages used worldwide by developers on many platforms. With Java, we can create cross-platform modern applications for multiple purposes.

JDK (Java Development Kit) contains a complete set of Java tools required for development:

  • the Java Runtime Environment (JRE),
  • an interpreter/loader (java),
  • a compiler (javac), an archiver (jar),
  • a documentation generator (javadoc)
  • and other tools needed in development.

In this article, we will focus on OpenJDK which is an open-source implementation of Oracle JDK. It was released in 2007 by Sun Microsystems that started working on this language in 2006.

2. Prerequisites

You must be logged in as a user with sudo privileges.

3. Installing default OpenJDK (the latest version)

To install OpenJDK in the latest available version please follow the below steps. At the time this article was writing the latest LTS version of Java was version 11.

1. On the first step we should update apt package index using the following command:

sudo apt update

2. When the package index is updated install the default Java OpenJDK package with:

sudo apt install default-jdk

3. To verify the installation, enter below command that will print the Java version:

java -version

The output of this command should look, more or less like:

openjdk version "11.0.3" 2019-02-23
OpenJDK Runtime Environment (build 11.0.3+9-Ubuntu-3ubuntu118.04.3)
OpenJDK 64-Bit Server VM (build 11.0.3+9-Ubuntu-3ubuntu118.04.3, mixed mode, sharing)

4. Installing OpenJDK 8

Java 8 is still very popular because it brings a lot of new and interesting features to the programming world. Follow these steps if you need to install OpenJDK 8:

1. First, update the APT package repository with the following command:

sudo apt update

2. To install Java OpenJDK in version 8 use the following command:

sudo apt install openjdk-8-jdk

5. Installing OpenJDK 12

OpenJDK 12 has two versions: full and headless. If you don't need to run the Java application that required standalone GUI uses a headless version.

1. First, update the APT package repository:

sudo apt update

2.1. Install Java OpenJDK 12 full version with the following command:

sudo apt install openjdk-12-jdk

2.2. Install Java OpenJDK 12 headless version with the following command:

sudo apt install openjdk-12-jdk-headless

6. Conclusion

In this article, we described how to install various versions of OpenJDK on Ubuntu. The process of installation is easy - mostly required only three commands entered on the console. Oracle JDK from version 11 will require a commercial license, so OpenJDK is a great alternative for those who don't want to pay.

{{ message }}

{{ 'Comments are closed.' | trans }}