/ JavaFX / Change Java version on Mac OS

Change Java version on Mac OS

Hendrik on 2013/02/08 - 23:52 in JavaFX

I’m currently working with JDK 6, 7 and 8 on my MacBook and it’s really a pain to switch between this Java version by shell. Because of that I created a tool that can do all the work for you:

cjv The tool shows all Java version that are currently installed on your system and you can switch between them just by a mouse click. The new version will work in any new shell and for every application that is started after switching the version. If you switch to JDK 8 and start Eclipse after that, the IDE will use JDK 8 as default JDK. If you need JDK 7 you have to restart Eclipse after switching the version. To set a new version the root password is needed because the tool will edit your “/env/launchd.conf” file.

You can download the tool as runnable JAR here or build it by your own. The sources are hosted at github.

How does the tool work

As you can read here the “/usr/libexec/java_home -V” command will show you all installed Java versions. The tool executes the command and parses the output. All found versions are displayed in a JTable. When setting a new version the tool will update the “/env/launchd.conf” file and sets the JAVA_HOME environment in this file. Any old JAVA_HOME environment will be removed. Then the tool calls a shell command that will update the OS environment by using the launchd.conf. You can read more about this function here. The root password is needed because “sudo” is needed to edit the “launchd.conf” file.

I hope the tool will be for be as useful as it is currently for me. If you have any problems, bugs or feature requests please fill a issue at github or write me a mail.


Send Us A Message Here

Your email address will not be published. Required fields are marked *

  • 2013/02/09

    Cool Tool 🙂 Thank you very much.
    I would like to know though how you hande the installation of a new JDK. Especially handling of the plugin and control panel part which always seem to be overwritten by the newes Java version. When you switch the java version, which version will be affected by the security settings you make in the control panel?

  • 2013/09/14

    Thanks a lot.
    You saved my time. ^^b

  • Pingback:Tools for app (and web) development on Mac | Sensai Touch

  • 2014/10/08


    I tried your tool and would like to say that I would find it extremely useful. Thank you for putting effort in this.
    However, it does not work for my OS X 10.9.4 (13E28). I have Java 6,7,8 and tried to switch.

    $ sudo java -jar /Applications/jvc.jar
    grep -E “^setenv” /etc/launchd.conf | xargs -t -L 1 launchctl
    launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_08.jdk/Contents/Home

    After that I opened another terminal and found the version unchanged.

    Am I doing something wrong or is this a bug?

    My Java versions reside in two different locations
    $ ls /System/Library/Java/JavaVirtualMachines/
    $ ls /Library/Java/JavaVirtualMachines
    jdk1.7.0_08.jdk jdk1.8.0_20.jdk

    • 2014/10/08

      the switch I tried was 1.8 -> 1.7

      • 2014/10/08

        Please let me correct myself, it was my mistake that it was not working. I had an export in my rc file that overwrote setting JAVA_HOME.

  • 2015/02/18

    I appreciate your effort in coming up with this tool and sharing it with everyone. Thanks!

    Does this work in OSX Yosemite? I just tried it and see no effect.

    Also how can one undo the configuration changes after using this tool?

    Karthic Raghupathi
    • 2015/02/19

      I never tried this with Yosemite. All the changes should be removed after a restart.

  • Pingback:Switching between JDKs and Displaying Hidden Files on OSX 10.9.5 | PragmaTek Solutions

  • 2016/01/28

    launchd.conf is no longer in use in El Capitan, so this does not work on it.

    Gui Correia