How-To Guides How to set JAVA_HOME Environment Variable MacOS

How to set JAVA_HOME Environment Variable MacOS

In this tutorial, we show you how to set $JAVA_HOME environment variable on your Mac OS X.

Mac OSX 10.5.x or later

Open the Terminal program present in your  (this is in your Applications/Utilities folder by default). Follow the below steps.

Step-1 Open and edit .bash_profile file

open -e .bash_profile

Step-2 Save the below line

export JAVA_HOME=$(/usr/libexec/java_home

Step-3 Refresh the file using below command

$ source .bash_profile

Step-4 Check if the JAVA_HOME is set properly

$ echo$JAVA_HOME
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home

For Older Mac OS X

For older Mac OS X, you have to use the full path of installation directory as it /usr/libexec/java_home doesn’t exists.

$ open -e .bash_profile
$ exportJAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
$ source .bash_profile

$ echo$JAVA_HOME
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Total
1
Shares
guest
0 Comments
Inline Feedbacks
View all comments
Previous Post

How to Install ant in your Mac OS X

Next Post
Copying the Contents of One text file to Another in Java

ServletContextListener Example in Servlet

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
0
Would love your thoughts, please comment.x
()
x