Linux JAVA_HOME variable with examples

Home > Search
  by

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

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments