Unable to locate an executable at "/usr/bin/java/bin/java" (-1)

JavaMacosJavac

Java Problem Overview


I am having a pathetic issue with Java in my mac osx 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 :

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Users/sabya/Documents/Play_Framework/play-2.0:/usr/X11/bin:/usr/local/git/bin:/usr/local/mysql/bin

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

Output of which java

/usr/bin/java

Its bugging me for long days and uninstalling and installing java did not help my luck .

I am a newbie in Mac and need help to sort out this issue .

Googled and saw SOF before posting this question but did not find anything specific to my problem .

Thanks

Sabya

Java Solutions


Solution 1 - Java

Most certainly, export JAVA_HOME=/usr/bin/java is the culprit. This env var should point to the JDK or JRE installation directory. Googling shows that the best option for MacOS X seems to be export JAVA_HOME=/Library/Java/Home.

Solution 2 - Java

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home

Because:

 $ find /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home -name java*
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/javac
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/javadoc
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/javafxpackager
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/javah
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/javap
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/javapackager
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/javafx-src.zip
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/bin/java

Solution 3 - Java

JAVA_HOME is not the name of the java executable. But of the directory, java was installed in. The executable should be $JAVA_HOME/bin/java.

The which command is not helpful for you there. It will not give you the java home, but most likely this is just a wrapper or symlink to java installed in a very different directory.

Solution 4 - Java

i have experienced the same problem, and after reading this post i have double checked the JAVA_HOME definition in .bash_profile. It is actually:

export JAVA_HOME=$(which java)

that, exactly as Anony-Mousse is explaining, is the executable. Changing it to:

export=/Library/Java/Home

fixes the problem, tho is still interesting to understand why it's valued in that way in the profile file.

Solution 5 - Java

In MacOS Catalina, run

sudo nano ~/.bash_profile

In bash_profile, add:

export JAVA_HOME=$(/usr/libexec/java_home)
source ~/.bash_profile

Verify by running java --version

Solution 6 - Java

For me, the problem occurs when I've downloaded macOS Compressed Archive which underlying directory contains

jdk-11.0.8.jdk
- Contents
  - Home
    - bin
    - ...
  - MacOS
  - _CodeSignature

So, to solve the problem, JAVA_HOME should be pointed directly to /Path-to-JDK/Contents/Home.

Solution 7 - Java

For those using newer versions of java: jhat has been removed since Java 9. Source: https://www.infoq.com/news/2015/12/OpenJDK-9-removal-of-HPROF-jhat/

That same article recommends using Java VisualVM instead.

Solution 8 - Java

I faced the same problem. Updating bash_profile with the following lines, solved the problem for me:

export JAVA_HOME='/usr/'

export PATH=${JAVA_HOME}/bin:$PATH

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSabyaView Question on Stackoverflow
Solution 1 - JavaAlexander PavlovView Answer on Stackoverflow
Solution 2 - JavaAnkur AgarwalView Answer on Stackoverflow
Solution 3 - JavaHas QUIT--Anony-MousseView Answer on Stackoverflow
Solution 4 - JavaBruno RipaView Answer on Stackoverflow
Solution 5 - JavaCri_NoxView Answer on Stackoverflow
Solution 6 - JavaEsmaeil MIRZAEEView Answer on Stackoverflow
Solution 7 - JavaasherbretView Answer on Stackoverflow
Solution 8 - JavaiamtesterView Answer on Stackoverflow