Ubuntu Linux

How to Install OpenJDK 11 in Ubuntu 18.04

OpenJDK 11 is the latest version of the Java development kit for Ubuntu 18.04. OpenJDK provides an open source Java implementation of the Java programming language.

OpenJDK 11 is available from the default Ubuntu 18 software repository, so installing Java 11 on Ubuntu is very easy.

Login to your Ubuntu system, Open the terminal and install the openjdk-11-jdk-headless package:

sudo apt-get update
sudo apt-get install openjdk-11-jdk-headless
How to Install OpenJDK 11 in Ubuntu 18.04

The openjdk-11-jdk-headless package contains both Java 11 runtime environment (Which you need to run Java applications) and Java development kit (which you need to develop Java applications).

Set Default Java version

If you have multiple Java versions installed on your Ubuntu system and if Java 11 is not the default version, then you need to run the update-alternative command to configure default Java version.

To configure the default Java runtime environment, run:

sudo update-alternatives --config java

Type the selection number of the Java version you wish to use as the default and press enter.

Set Default Java version in Ubuntu 18

To configure default Java compiler version, run:

sudo update-alternatives --config javac

Type the selection number of the Java compiler version you wish to use as the default and press enter.

After that, run the java -version command to check the Java version:

java -version
check the Java version in Ubuntu 18.04.

Add OpenJDK 11 to the JAVA_HOME variable

The following are the steps to configure JAVA_HOME environment variable:

Open the /etc/bash.bashrc file and add the JAVA_HOME and PATH variable at the end of the file.

export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin

Save and source the bash.bashrc file:

source /etc/bash.bashrc

Echo the  JAVA_HOME variable to make sure that variable has been set:

echo $JAVA_HOME

Now we OpenJDK installed on our Ubuntu 18.04 system, So the next thing we are going to do is install a JAVA IDE. There are several integrated development environment for Ubuntu, But the best three by far are: IntelliJ IDEA, Eclipse and NetBeans IDE.