Change Java version on Mac OS

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.

6 Responses to Change Java version on Mac OS

  1. 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?

  2. Hi,

    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/
    1.6.0.jdk
    $ ls /Library/Java/JavaVirtualMachines
    jdk1.7.0_08.jdk jdk1.8.0_20.jdk

Hinterlasse eine Antwort

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>