Last Updated: October 04, 2020
· gamussa

Set default JDK on Mac OS X

Apple announced to remove Java Preferences app from Mac OS X Let's try to fix it. Generally, java applications will use the JAVA_HOME environment variable to pick a JDK.

To set to JDK 6

export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)

To set JDK 7

export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)

To set JDK 8

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

Created aliases for my zsh

alias setjdk16='export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)'
alias setjdk17='export JAVA_HOME=$(/usr/libexec/java_home -v 1.7)'
alias setjdk18='export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)'

For exotic cases, like Netbeans follow instruction here


Related protips:

How To Check If JDK Is 32-bit or 64-bit?

1 Response
Add your response

Thank you for the article, it helped me a lot.

over 1 year ago ·