About Senthil

all about senthil

How to set JAVA_HOME in MAC

By admin | November 28, 2016 | 0 Comment

1. Mac OSX 10.5 or later

In Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME variable to /usr/libexec/java_home, just export $JAVA_HOME in file ~/. bash_profile

$ vim ~/.bash_profile

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

$ source ~/.bash_profile

$ echo $JAVA_HOME

Why /usr/libexec/java_home?
This java_home can return the Java version specified in Java Preferences for the current user. For examples,

Senthilkumars-MacBook-Air:$ /usr/libexec/java_home -V

Matching Java Virtual Machines (1):

    1.8.0_111, x86_64: “Java SE 8” /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home


2. Older Mac OSX

For older Mac OSX, the /usr/libexec/java_home doesn’t exists, so, you should set JAVA_HOME to the fixed path :

$ vim ~/.bash_profile

export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home

$ source ~/.bash_profile

$ echo $JAVA_HOME


Leave a Reply

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