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