Install Oracle JDK with Apt-Get on Linux

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

For Oracle JDK8,

sudo apt-get install oracle-java8-installer

For Oracle JDK9,

sudo apt-get install oracle-java9-installer

There can be multiple Java installations on one server. You can configure which version is the default for use in the command line by using update-alternatives, which manages which symbolic links are used for different commands. You can now choose the number to use as a default.

sudo update-alternatives --config java

To set this environment variable, we will first need to find out where Java is installed.

Copy the path from your preferred installation and then open /etc/environment

sudo nano /etc/environment

And add the following line,

JAVA_HOME="path-of-jdk-or-jre"

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

Save and exit the file. Now reload it.

source /etc/environment

check whether the environment variable has been set

echo $JAVA_HOME
mm

Anup Chhetri

IT system administrator

You may also like...

error: Content is protected !!