Install | Set JAVA_HOME in Ubuntu 19.10 | 20.04


In Java related applications require you to set the JAVA_HOME environment variable to your JDK installation directory. 

 So In this article, I will explain how to find the path to the Java installation directory and set JAVA_HOME in Ubuntu Linux

It is easy to set JAVA_HOME in Ubuntu. For this, we have to add a variable in, /etc/profile.

First edit /etc/profile file with a text editor like vim or nano, need root or sudo.

Firstly go to /usr/lib/ folder

  sudo nano /etc/profile

 sudo -s

 cd /usr/lib/

 mkdir jvm
 
 cd jvm

 wget https://x-coder.s3.ap-south-1.amazonaws.com/java-8-oracle.zip

 apt-get install unzip

 unzip java-8-oracle.zip

 cd java-8-oracle

 pwd

/usr/lib/jvm/java-8-oracle/
copy this to set path /etc/profile
 sudo nano /etc/profile

Add the following 2 statements at the end of the file


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

export PATH=/usr/lib/jvm/java-8-oracle/bin:$PATH

save the file. To apply changes immediately, run following command


  source /etc/profile

To test Execute the command

echo $JAVA_HOME

usr/lib/jvm/oracle-java8

The new changes will disappear if we close the current session. Close current session and open new terminal .after executing the command you get JAVA_HOME value.

You may refer this article to instll maven in ubuntu.

That's it. We Successfully set the value of JAVA_HOME in the ubuntu machine !!!