Install Java JDK on Linux Ubuntu from SSH terminal in few simple steps, setting the JAVA_HOME environment variable.

What is Java JDK

Java JDK, an acronym for Java Development Kit, is software that enables the development, compilation and execution of applications developed with the Java language.

Java JDK differs from Java JRE in that, the first one is a complete software that includes everything needed to run and develop Java applications, while the latter includes only what is needed to run programs.

WARNING. The steps below should be performed by experienced people as they are potentially dangerous and could damage the server. If you do not know what you are doing you can request a free quote.

Install Java JDK su Linux

Beforeinstalling Java JDK on Linux Ubuntu, as a first step, check that it is not already installed on the server

javac -version

If the server respond with a line like this

Command 'java' not found, but can be installed with:

means that you have to install Java on the server with the command

sudo apt install default-jdk

By re-launching the following command, you should now see the version of the JDK you just installed returned

java -version

Configuring the JAVA_HOME environment variable on Linux

Many softwares require setting environment variable JAVA_HOME, which is used to locate the default version of Java within the system. In order to set the JAVA_HOME as first thing check the versions of JAVA JDK installed on the system

sudo update-alternatives --config java

Copy the folder path of the desired version, for example the default version of JAVA JDK for Ubuntu 20.04 is


Edit the environment file by adding to the end of the file


Reload the environment file with

source /etc/environment

To verify that procedure was successful, all you have to do is print the JAVA_HOME variable you just set with


if it returns the java folder chosen as the default previously, everything was successful


Linux Support Quote

    Contact us for a free quote