Recently I had to setup a Java app on my Mac, which was running from the Terminal, and needed the JAVA_HOME variable set.
Here’s what had to be done:
– Start the Terminal app.
– Create/Edit ~/.bash_profile file.
Note: I first tried creating and using the ~/.bashrc file, but that didn’t work (Mac OS 10.6.2), while ~/.bash_profile worked as expected.
Therefore,
$ vi ~/.bash_profile
… and paste the following (make it a single line):
export JAVA_HOME=/System/Library/Frameworks/
JavaVM.framework/Versions/CurrentJDK/Home
… save and exit vi.
Restart Terminal app just to be sure that it worked, and try accessing it by typing:
$ echo $JAVA_HOME
If you see the correct JAVA path, then it is all done!
Thanks for the pointer mate.
Thanks for this info.. I am trying to do the same thing and opening the terminal and pasting “$ vi ~/.bash_profile” gives me a “-bash: $: command not found” reply. Any ideas?
Regards
Hi, just start from vi not the dollar sign.
[…] Recently I had to setup a Java app on my Mac, which was running from the Terminal, and needed the JAVA_HOME variable set. Here's what had to be done: – Start the Terminal app. – Create/Edit ~/.bash_profile file. Note: I first tried creating and using the ~/.bashrc file, but that didn't work (Mac OS 10.6.2), while ~/.bash_profile worked as expected. Therefore, $ vi ~/.bash_profile … and paste the following (make it a single line): export JAVA_HO … Read More […]
Thank you for this sweet tip on setting JAVA_HOME on MacOS. It worked like a charm
I have wasted two days trying to get JavaDB working on my Macbook Pro. You gave me the lightbulb moment that allowed me to get it working. THANK YOU!!!!!!!!!!! This post is a gift that is still giving 2 years later. I wanted you to know.
The proper way to set JAVA_HOME on OS X is to export JAVA_HOME=`/usr/libexec/java_home`, because it respects the settings from the Java Preferences app, and works for non-Apple JVMs (eg. Oracle JVM).
Thank you!
@daniel serodio
thx for yr comment
[…] following instructions from: here […]
[…] following instructions from: here […]
I am stuck, anyone got pointers? Im not a mac guy and my windows machine broke. So I need to try to get this working with my mac. Everytime I vi /.bash_profle, i get a “~” per line without anything there. Then when I type export JAVA_HOME=/System/Library/Frameworks/
JavaVM.framework/Versions/CurrentJDK/Home I cannot save it. How do you save? cmd s does an export text. CTRL O does nothing.
Hey guys, IM A MORON. Sorry, forgot to mention that.
NVMD I GOT IT
Hi. I am new to Mac in terms of programming. I have a question regarding the method. I have done the way was shown above. I think it worked. However I have few questions. First, does it work for any version of java idk?? The CurrentJDK from the this sentence, export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home, does it apply for any current idk version? or do I need to specify the version like jdk 1.7.0.71?? And one more question is that, I’ve been searching around the web and found out that for the Mac OS 10.5 or later, they create something called libexec. Do i need to do that?.. Sorry for my poor english but I would like to get some help..