Installing OpenJDK on Ubuntu Server | Information Technology from Valdemar

This article is written for those who were searching for a detailed and simple for the understanding guide on how to install OpenJDK on Ubuntu Server.

With the release of Java 11, Oracle JDK has become commercial and is no longer free.

OpenJDK is an open-source implementation of the Java Standard Edition platform with the participation of Oracle and the open Java community. The build process for the Oracle JDK is built from the OpenJDK source code, so there is no big difference between the Oracle JDK and OpenJDK.

OpenJDK is free but will have to be updated every 6 months.

In this guide, we will consider the case when you already have a server with the Ubuntu Server 18.04 LTS operating system installed on it.

You can read more about how to install Ubuntu Server 18.04 LTS in my guide «Installing Ubuntu Server 18.04 LTS».

In addition, OpenSSH must be installed on the server, and port 22 must be open in order to be able to connect to the server using the SSH protocol.

To install OpenSSH on the server, you can use the command:

sudo apt-get install openssh-server

If you plan to connect to the server using the Windows operating system, you can use PuTTY, a freeware client for various remote access protocols, including SSH, Telnet, rlogin.

This guide covers connecting to a server using the iTerm2 terminal emulator installed on the macOS operating system.

Connect to the server on which it is planned to install OpenJDK.

Next, you need to confirm that we trust the server to which we are connecting.

Enter “yes” and press the “Enter” button.

Update the local package index to the latest changes in the repositories using the command:

sudo apt-get update

You may need the Java Development Kit (JDK) in addition to the JRE in order to compile and run certain Java-based software.

To install the JDK, run the following command, which will also install the JRE:

sudo apt-get install -y default-jdk

Now you need to make sure that OpenJDK is installed correctly. To do this, run the command:

java -version

Judging by the message received, OpenJDK is installed correctly.

Many programs written using Java use the “JAVA_HOME” environment variable to determine where to install Java. Therefore, you must define this variable and assign it a value containing the path to the Java installation location.

Define the path to the Java installation location using the command:

sudo update-alternatives --config java

В данном примере путь к месту установки Java выглядит так:

/usr/lib/jvm/java-11-openjdk-amd64/bin/

In order to define an environment variable and assign a value to it, you need to make changes to the “environment” file by opening it in a text editor using the command:

sudo vim /etc/environment

Press the “i” button to enter the editing mode, then at the end of the file, define a new variable “JAVA_HOME” and assign it a value containing the path to the Java installation location obtained earlier.

JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/bin/"

Please note that the path to the Java installation location must be specified to the “bin” folder inclusively.

Now press the “Esc” button to exit the editing mode, and then enter “: x” and press the “Enter” button to save the changes and exit the editor.

Next, you need to apply the changes to the current session using the command:

source /etc/environment

Now make sure that the environment variable has the correct value using the command:

echo $JAVA_HOME

Judging by the message received, the environment variable has the correct value.

Author

Hi, I’m Vladimir Mikhalev, but my friends call me Valdemar. I have a lot of experience in the design and maintenance of various information systems. On my website, you will find detailed and clear guides for setting up IT solutions. Dive into the ocean, full of positive and technology! For cooperation: callvaldemar@gmail.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.