Java - Linux JAVA_HOME variable with examples
by
Jeremy Canfield |
Updated: September 10 2023
| Java articles
Before setting the JAVA_HOME variable, you first need to determine where the Java binary is in your 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
Temporarily set JAVA_HOME
The export or set commands can be used to temporarily set the JAVA_HOME variable.
[john.doe@server1 ]# export JAVA_HOME="/usr/lib/jvm/java/"
[john.doe@server1 ]# set JAVA_HOME="/usr/lib/jvm/java/"
Echo $JAVA_HOME to confirm the variable now has /usr/lib/jvm/java/.
[john.doe@server1 ]# echo $JAVA_HOME
/usr/lib/jvm/java/
Permanently update PATH
The JAVA_HOME variable can be set in the /etc/profile file.
export JAVA_HOME="/usr/lib/jvm/java/"
The source command can be used to reload the /etc/profile file after making the change, which will reload the file, including the JAVA_HOME variable.
[john.doe@server1 ]# source /etc/profile
Did you find this article helpful?
If so, consider buying me a coffee over at