Java Environment Variables

Java Home

Sometimes you have multiple Java environments on a machine and you might have some interesting scripts, so you need to set the JAVA_HOME environment variable. Alternatively you might be using Java based products like Apache Tomcat for example that like or need the JAVA_HOME to be set. Normally JAVA_HOME points to a Java Development Kit as a number of tools will expect the extra utilities over the Java Runtime Environment (JRE). It is worth being clear that JAVA_HOME should point to the JDK root directory.

Windows

So for example on Windows you might have this:
JAVA_HOME=C:\Progra~1\Java\jdk1.8.0_60
The intention is that the following will work:
%JAVA_HOME%\bin\java -version
This example is Windows based but is very similar on Unix/Linux.
On a Windows platform, where Java can struggle with the space character in the path you will notice I have used the Short FileName (8.3 filename) directory names. If you need to fathom these out for your own directories then dir /x is your friend.

Linux

With Linux you can find the default java with which java, which will most likely lead to a softlink, so "ls -l" will show where that points to, if it is in an "alternatives" directory then consult your distribution documentation for how to change this.
If you need help setting the JAVA_HOME on Linux then see Linux Profile for further details.
Ideally you need to make sure the following lines both give the same output:
java -version
$JAVA_HOME/bin/java -version

If they are different then your default is not consistently set.