Skip to content
James Phelps edited this page May 11, 2020 · 12 revisions

Overview

Several options exists for install the JDK in ubuntu. My preferred version is to Install with SDKMAN! How to install SDKMAN! is described here

Then all you have to do is list all possible jdk that can be installed with the following command:

sdk list java

We can now install OpenJDK 8 with the following command:

sdk install java 8.0.252-open

you have to adapt the version for your needs.

Now install OpenJDK 11 with the following command:

sdk install java 11.0.7-open

you will be asked if the current installed jdk should be the default answer with Y you have to adapt the version for your needs.

Now you can switch easily through the installed JDK versions.

For temporary switch to OpenJDK 8 use the following command:

sdk use java 8.0.252-open

if you want it to set it as default use the following command:

sdk default java 8.0.252-open

So easy.

If you want to set the path for a specific JDK(for instance in an ide like eclipse) there are saved at

~/.sdkman/candidates/java

Install from repository ppa:webupd8team

For install the java jdk you have to add a repository. This is the ppa:webupd8team/java. You do that with the following command:

sudo add-apt-repository ppa:webupd8team/java

No you can update:

sudo apt-get update

JDK 8 install

For install the JDK 8 and set to default you have to execute the following command:

sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java8-set-default

A detailed install description of install jdk8 on ubuntu is on this link webupd8.org jdk8

JDK 9 install

For install the JDK 9 and set to default you have to execute the following command:

sudo apt-get install oracle-java9-installer
sudo apt-get install oracle-java9-set-default

A detailed install description of install jdk9 on ubuntu is on this link webupd8.org jdk9

JDK higher then version 9 install

A detailed install description of install jdk higher then version 9 on ubuntu is on this link digitalocean.com install jdk

Set JAVA_HOME

There are several options to set JAVA_HOME on linux but the prefered options is to set it in the file 'etc/environment' as described here

JAVA_HOME="/usr/lib/jvm/java-8-oracle"

You can write this line to the file 'etc/environment' from the shell console and display the content for review with the following commands:

sudo awk 'BEGIN{ printf "JAVA_HOME=\"/usr/lib/jvm/java-8-oracle\"" >> "/etc/environment"  }'
awk '1' /etc/environment

The same effect as above have the following commands:

sudo echo "JAVA_HOME=/usr/lib/jvm/java-8-oracle" >> /etc/environment
source /etc/environment

Now check if the environment variable JAVA_HOME is correctly set review with the following command:

echo $JAVA_HOME
Clone this wiki locally