The Golden Spot

I hope this helps someone who is learning about Linux and web application programming with Python, Django, and Javascript.

Thursday, September 11, 2014

Multiple Java versions on my mac

I have Java 8 JDK installed and I would like to use Scala but it works much better with Java 7 JDK at the moment. My solution was to install Java 7 SDK and create bash functions in my bash startup file, in my case .bashrc

function java8() { 
   export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home } 

function java7() { 
   export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home }

The above functions swap the JAVA_HOME environment variable which causes the respective Java version to be used[1]. Example:


computer ~ $ java8 
computer ~ $ java -version 
java version "1.8.0_05" 
Java(TM) SE Runtime Environment (build 1.8.0_05-b13) 
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode) 
computer ~ $ java7
computer ~ $ java -version 
java version "1.7.0_67" 
Java(TM) SE Runtime Environment (build 1.7.0_67-b01) 
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)


[1] http://java.dzone.com/articles/multiple-versions-java-os-x


0 Comments:

Post a Comment

<< Home