I had installed java a while ago on my RHEL machine. Now, I’m trying to run a program that requires the JAVA_HOME variable to be set. What is the best way to figure out the installation directory of my java installation and then set JAVA_HOME? Here are the results of running java- version :
java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
I have a /usr/lib/jvm directory, but it is empty.
echo $JAVA_HOME from the command line. Since
java is on your path already,
JAVA_HOME may be set.
What is the best way to figure out the installation directory of my java installation
Running the command
which java will point you to where
java is installed.
and then set JAVA_HOME
You can edit
/etc/profile to set
JAVA_HOME. Setting it in
~/etc/profile will set it system wide, and this is probably not what you want. Say for the sake of example the output of
which java is
/opt/jdk_1.7.0_25, then you’d just add
export JAVA_HOME=/opt/jdk_1.7.0_25 to
~/.bash_profile and then run
source ~/.bashrc (or
source ~/.bash_profile if you set it there).
Note that in this case,
java is on the
PATH but in some cases you’d need to add
export PATH=$PATH:$JAVA_HOME/bin to add the
JAVA_HOME variable to the
Answered By – rpmartz