What do I set as JAVA_HOME?
Question
I just installed Ubuntu desktop 12.04 and installled Java 6 JDK via:
sudo apt-get install openjdk-6-jre
When I issue a `java -version command, I get:
OpenJDK Runtime Environment (IcedTea6 1.11.3) (6b24-1.11.3-1ubuntu0.12.04.1) OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
When I issue a 'which java` command, I get:
/usr/bin/java
But when I go to /usr/bin/
, I don't see a directory named java
, so I don't think it's even there!?!
When I go to /usr/lib/jvm/
, I see:
-rw-r--r-- 1 root root 2387 Jun 27 05:21 .java-1.6.0-openjdk-amd64.jinfo
drwxr-xr-x 5 root root 4096 Aug 31 19:28 java-6-openjdk-amd64
drwxr-xr-x 3 root root 4096 Aug 31 19:28 java-6-openjdk-common
drwxr-xr-x 5 root root 4096 Aug 31 19:28 java-7-openjdk-amd64
I'm now trying to add JAVA_HOME
as an environmental variable to ~/.bashrc
so I can access it from inside my shell-based Ant builds:
export JAVA_HOME=???
I'm not sure what to set as the value for JAVA_HOME
:
/usr/bin/java
?/usr/lib/jvm
?- Something else?
By "JAVA_HOME
", I mean the top-level directory of the JDK 6 install that I have on my system, wherever that is...
Solution
I don't have $JAVA_HOME configured on my Linux box - and I don't recall a time ever needing to do so.
When you're looking in /usr/bin
, you're looking at binaries - hence bin. A quick look at what the file is would reveal that it's a symbolic link, which points a symbolic link which points to wherever your Java installation resides.
$ file `which java`
/usr/bin/java: symbolic link to `/etc/alternatives/java'
It is a better choice to let the system configure it for you - either through the use of update-alternatives or update-java-alternatives - the latter being preferred to switch over entire versions of Java entirely.
OTHER TIPS
Let the system configure it for you
sudo update-alternatives --config java
For further reference, see Choosing the default Java to use of the Ubuntu documentation.