Bootstrap FreeKB - Java - Linux JAVA_HOME variable with examples
Java - Linux JAVA_HOME variable with examples

Updated:   |  Java articles

Before setting the JAVA_HOME variable, you first need to install Java and determine where the Java binaries are in your system. Check out my article FreeKB - Java - Install Java on Linux for more details on installing Java on a Linux system.

The find command can be used to locate the Java binary. In this example, the Java binary is located at /usr/lib/jvm/java.

[john.doe@server1 ~]# find / -iname java
/usr/lib/jvm/java

 

The JAVA_HOME is the path to the Java directory that contains the bin folder. For example, if your JAVA bin directory is located at /usr/lib/jvm/adoptopenjdk-21.0.4.7/jdk-21.0.4+7

~]$ ll /usr/lib/jvm/adoptopenjdk-21.0.4.7/jdk-21.0.4+7
total 24
drwxr-xr-x.  2 root root 4096 Jul 16 18:41 bin
drwxr-xr-x.  5 root root  146 Jul 16 18:40 conf
drwxr-xr-x.  3 root root  132 Jul 16 18:40 include
drwxr-xr-x.  2 root root 4096 Jul 16 18:40 jmods
drwxr-xr-x. 71 root root 4096 Jul 16 18:40 legal
drwxr-xr-x.  5 root root 4096 Jul 16 18:41 lib
drwxr-xr-x.  3 root root   18 Jul 16 18:40 man
-rw-r--r--.  1 root root 2400 Jul 16 18:41 NOTICE
-rw-r--r--.  1 root root 1610 Jul 16 18:40 release

 

Then you would set JAVA_HOME to /usr/lib/jvm/adoptopenjdk-21.0.4.7/jdk-21.0.4+7. The export or set command can be used to temporarily set the JAVA_HOME variable.

export JAVA_HOME=/usr/lib/jvm/adoptopenjdk-21.0.4.7/jdk-21.0.4+7

 

Or you can set the JAVA_HOME variable in your .bash_profile file to make the JAVA_HOME variable permanent.

[john.doe@localhost ~]$ cat $HOME/.bash_profile 
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi


export JAVA_HOME=/usr/lib/jvm/adoptopenjdk-21.0.4.7/jdk-21.0.4+7

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 9e54a7 in the box below so that we can be sure you are a human.