Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having an issue with Java in my Mac (OS X 10.7.3). Previously I installed it and it was working fine. After some changes in the .bash_profile and .profile file in the course of time, I am having an error like Unable to locate an executable at "/usr/bin/java/bin/java" whenever I try to run "javac" or "java" in my terminal.

echo $PATH gives an output like:


My .bash_profile looks like:

alias start_mysql="/Library/StartupItems/MySQLCOM/MySQLCOM start"
alias stop_mysql="/Library/StartupItems/MySQLCOM/MySQLCOM stop"
export JAVA_HOME=/usr/bin/java

Its bugging me for several days and reinstalling Java did not help. I'm a newbie in Mac and need help to sort out this issue. I Googled before posting this question but did not find anything relevant.

share|improve this question
up vote 4 down vote accepted

You probably can just remove the definition of JAVA_HOME from .bash_profile and restart the shell. If you really need to set the variable, use

export JAVA_HOME=$(/System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java_home)

to define it dynamically depending on the installed JDK version or

export JAVA_HOME=/Library/Java/Home

to use the default place (which is symlinked to the above path).

share|improve this answer
Thanks for the help Patrix . – Sabya Jun 3 '12 at 20:09
Another trick worked . I just edited the .bash_profile and exported the JAVA_HOME as export JAVA_HOME=/Library/Java/Home . It solved the problem . – Sabya Jun 3 '12 at 20:12
Indeed :-) It's a symbolic link leading (after some more redirections) to the same place. I've extended the answer accordingly. – patrix Jun 4 '12 at 5:06
Frequently you do not even need JAVA_HOME – Thorbjørn Ravn Andersen Jun 5 '12 at 19:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.