Ubuntu 22.04

How To Set JAVA_HOME Environment Variable On Ubuntu 22.04

How To Set JAVA_HOME Environment Variable On Ubuntu 22.04
Written by itsubuntu

How To Set JAVA_HOME Environment Variable On Ubuntu 22.04

Before setting Set JAVA_HOME Environment Variable On Ubuntu 22.04 LTS, make sure that you have Java installed in your Ubuntu 22.04 LTS. If there is no JAVA installed in your Ubuntu, then please check out the following link:

How To Set JAVA_HOME Environment Variable On Ubuntu 22.04

JAVA is one of the most popular programming languages. Many programs are written using Java programming language and the program written on JAVA uses the JAVA_HOME environment variable to determine the Java installation location.

It’s confusing but easy to set the JAVA_Home environment variable on Ubuntu 22.04 LTS.

At first, you need to determine where JAVA is installed. Run the following update-alternatives command to find the path of JAVA installation.

sudo update-alternatives --config java

You might see the output something like below:

Output

Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
* 2 /usr/lib/jvm/java-11-oracle/bin/java 1091 manual mode

Press  to keep the current choice[*], or type selection number:

From the above output, you can figure out the location of the JAVA and its associate.

OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java and  Oracle Java is located at /usr/lib/jvm/java-11-oracle/jre/bin/java.

Now open /etc/environment using nano or your favorite text editor:

sudo nano /etc/environment

Go to the end of the file, and add the following line. Make sure that the path to the JAVA installation is correct

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

Save the file and exit the editor.

Now you need to reload this file to apply the changes to your current session:

source /etc/environment

if you want to verify that the environment variable is set then run the following command:

echo $JAVA_HOME

You will see the output something like below:

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

In this way, you can easily set the JAVA_HOME Environment Variable On Ubuntu 22.04 LTS. This tutorial will help you set the JAVA_HOME Environment Variable when you have installed the multiple versions of Java on Ubuntu 22.04 LTS

 

About the author

itsubuntu

Leave a Comment