Set $JAVA_HOME to latest java on OSX

First you may want to know which java versions you have installed, Use /usr/libexec/java_home -V to get a short overview:

$ /usr/libexec/java_home -V

Matching Java Virtual Machines (6):
    1.8.0_66, x86_64:           "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home
    1.8.0_60, x86_64:           "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home
    1.8.0_25, x86_64:           "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home
    1.7.0_17, x86_64:           "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home
    1.6.0_65-b14-468, x86_64:   "Java SE 6" /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
    1.6.0_65-b14-468, i386:     "Java SE 6" /Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home

Use lastest java version

Setting a static JAVA_HOME can be dangerous, after updateing java the path to java installation differs from previous one. Add following line to your .profile file, or .zshrc if you’re using zsh.

export JAVA_HOME=$(/usr/libexec/java_home)

Comments

comments powered by Disqus