How To Set JAVA_HOME Environment Variable On 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

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.

READ More Relevant Stuff:  Install Linux, Nginx, MySQL, PHP On Ubuntu 18.04 : LEMP Stack

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

 

1 Comment

  1. John

    here is what I get :*

    Exception in thread “main” java.lang.NoClassDefFoundError: javafx/application/Application
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    at com.xiaomitool.miunlock.Main.main(SourceFile:46)
    Caused by: java.lang.ClassNotFoundException: javafx.application.Application
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    … 10 more

Leave a Reply

Your email address will not be published. Required fields are marked *