Skip to main content

1 minute read - Java For Testers Mac

Switching between Java versions on a Mac

Jan 21, 2015

I just installed JDK 1.8 and had a problem:

  1. I could not figure out where JAVA_HOME was configured
  2. I wanted an easy way to switch between versions

After a bit of Google searching I learned about:

  • /usr/libexec/java_home
    • in
  • Finding/Setting JDK/$JAVA_HOME on Mac OS X
    • /usr/libexec/java_home
      • displays the current Java version in use
    • /usr/libexec/java_home -V
      • displays all current Java versions available
    • /usr/libexec/java_home -v1.6
      • displays the path for the specific version

And in the above article, I found a comment describing aliases.

I added the following aliases into my .profile

alias java6="export JAVA_HOME=`/usr/libexec/java_home -v1.6`"
alias java7="export JAVA_HOME=`/usr/libexec/java_home -v1.7`"
alias java8="export JAVA_HOME=`/usr/libexec/java_home -v1.8`"

After executing “source .profile” the aliases became active.

And now I can easily switch between the various versions of Java.

Notes:

  • Do not add spaces in the alias between java6 = "export or your alias won’t work
  • Other options are listed at mike.mainguy
  • Steve Bennett suggested jenv.be

You will need a Github account to comment. Or you can contact me with your comment.

I reserve the right to delete spam comments e.g. if your comment adds no value and its purpose is simply to create a backlink to another site offering training, or courses, etc.