Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have install java through yum on CentOS, however another java programme needs to know what the JAVA_HOME environmental variable is. I know all about setting environmental variables, but what do I set it to? java is installed in /usr/bin/java, it can't be there!

share|improve this question

6 Answers 6

up vote 21 down vote accepted

Actually I found it,

it's /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/. I found out what it was by doing update-alternatives --display java and it showed me the directory /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java

share|improve this answer

I'm not quite sure but if you install the normal RPMS the JAVA_HOME value can also be set to this:


EDIT: I just checked on my home system. I have created this file:


That contains:

export JAVA_HOME=/usr/java/default/

and I'm using the official version from Sun: jdk-1.6.0_12-fcs

EDIT: Here is how I set up Java on my machine:

Install Java

Download and install Java JDK from Oracle

Make it primary

Ensure this Java is used instead of the OpenJDK version using the following two commands:


alternatives --install /usr/bin/java java /usr/java/default/bin/java 999999 
           --slave /usr/bin/keytool keytool /usr/java/default/bin/keytool 
           --slave /usr/bin/rmiregistry rmiregistry /usr/java/default/bin/rmiregistry


alternatives --install /usr/bin/javac javac /usr/java/default/bin/javac 999999
           --slave /usr/bin/jar jar /usr/java/default/bin/jar
           --slave /usr/bin/rmic rmic /usr/java/default/bin/rmic


Ensure all users have their JAVA_HOME environment variable set to the correct value:

echo "export JAVA_HOME=/usr/java/default/" > /etc/profile.d/java_home.sh
share|improve this answer
oh interesting. :) –  Rory Aug 6 '09 at 13:19
There's no /usr/java/default in my CentOS 6 box with OpenJDK 1.6 and 1.7 installed. –  Daniel Serodio Oct 28 '13 at 17:11
@DanielSerodio Correct. I clearly described "Download and install Java JDK from Oracle", and then it does exist. –  Niels Basjes Oct 29 '13 at 9:06

You want to set JAVA_HOME to be the root location of the JDK or JRE, for example:

export JAVA_HOME=/usr/java/jdk1.3

If the JDK (Development kit) is installed, ypu probably want it to point to that, else use the JRE path (Java Runtime Environment). Then, you might want to set your $PATH environment variable to include the bin directory as well:

export PATH=$PATH:/usr/java/jdk1.3/bin

If you are using tomcat, you might also need to set CATALINA_HOME for the tomcat user.

export CATALINA_HOME=/path/to/tomcat

To set this for the system you want to edit your /etc/profile or add a .sh file in /etc/profile.d folder. For a particular user you can put it in the users ~/.profile or ~/.bash_profile files.

share|improve this answer
I wonder if there is a good reason the install doesn't do this for you if run as the super user, I always find it irritating ... –  Kyle Brandt Aug 6 '09 at 13:15

Below is always working form me perfectly:

[user@base ~]$ locate bin/java

It means I can set JAVA_HOME as /usr/java/jdk1.6.0_31

share|improve this answer

Thats weird, the whole point of having a JAVE_HOME environmental variable is so you don't have to specify the path to each program, it can get this path by looking for this variable.

Either way, the correct way to find the environmental variable for JAVA_HOME is to use echo:

[root@host ~]# echo $JAVA_HOME

Running this command will display the path no matter what version you are running, from command line.

share|improve this answer
The variable had not been set. –  Rory Aug 6 '09 at 13:19

You could just issue ls -al /usr/bin/java which is a link to {java_dir}/jdk/bin/java

Edit : this answer is assuming that you are trying to find the jdk directory, in this case it does not matter if you JAVA_HOME is set or not or may be set incorrectly

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.