Java 7 on Mac OS X 10.9.2 Mavericks

Well, it seems that Apple do not want to make things too easy for us Java developers.  Its own support for Java expired with Java 6, and Java 7 is a much more manual affair.  Moreover there is no auto update path to get from one to the other.

In order to install the JDK on Mac OS X 10.9.2, I had to jump through the following hoops:

  • Download the installation disk image file here.
  • Run the installation, which will install the JDK in 
    /Library/Java/JavaVirtualMachines
    
  • From the command line, enter
    java -version
    
  • This may correctly update the CurrentJDK symlink… or it may not. If it doesn’t, you need to do the following:
  • Navigate to
    /System/Library/Frameworks/JavaVM.framework/Versions/
    
  • rm CurrentJDK
    
  • ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/ CurrentJDK
    

java -version should now return the required version. However, this doesn’t set the environment variable JAVA_HOME which is required by many apps. While java -version returns the version, JAVA_HOME contains the path to the JDK. To set it, do the following:

echo "export JAVA_HOME='/usr/libexec/java_home'" >> ~/.profile

That’s it.  You should now have Java 7 up and running as your default Java version on your Mac.