Jdk
On Mac OS /usr/bin/java and friends are stubs that delegate real JDK commands. These stubs respect the setting of your JAVA_HOME environment variable, but for this you need to install the JDK (from http://www.oracle.com/technetwork/java/javase/downloads/index.html ), unlike JRE (from http: / /java.com ).
The JDK is installed in /Library/Java/JavaVirtualMachines/jdk1.7.0_NN.jdk (for any NN value), so set the JAVA_HOME environment variable to /Library/Java/JavaVirtualMachines/jdk1.7.0_NN.jdk/Contents/Home to do /usr/bin/java use 1.7. You can go back to 1.6 simply by pointing JAVA_HOME instead to /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home . You can use the /usr/libexec/java_home to automatically find the correct value, for example to make /usr/bin/java use Java 7, which you can do
export JAVA_HOME=`/usr/libexec/java_home -v '1.7*'`
and so that it uses Java 6 you can do
export JAVA_HOME=`/usr/libexec/java_home -v '1.6*'`
The same goes for Java 8 (using -v '1.8*' ). This will select the latest installed JDK for the corresponding major version, you should not forget to change NN manually when installing the update.
Jre
If you want to run 1.7 or 1.8 JRE from the command line, it can be found in /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java . This is a fixed path, and you can install only one โpublicโ JRE at any given time.
$ /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version java version "1.7.0_13" Java(TM) SE Runtime Environment (build 1.7.0_13-b20) Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
You can use a shell alias in your .bashrc
alias java_jre='/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java'
Ian Roberts Mar 25 '13 at 21:57 2013-03-25 21:57
source share