0

Our help desk already installed Java 1.8_151 on our macbook pro Mohave. When I type 'which java' I get the reply as /usr/bin/java

So, I added these two lines in my .bash_profile file in my home folder /Users/pnutalap

export JAVA_HOME=/usr/bin/java
export PATH=$JAVA_HOME/bin:$PATH

When I checked immediately 'java -version' I got back the java version correctly. But today, I am getting totally different resonse like...

N201960-MAC:~ pnutalap$ java -v Unable to locate an executable at "/usr/bin/java/bin/java" (-1)

Why there is additional /java at the end ? What has gone wrong ? And how to correct it to show java version properly ?

PraNuta
  • 629
  • 3
  • 12
  • 33
  • 2
    Possible duplicate of [What should I set JAVA\_HOME to on OSX](https://stackoverflow.com/questions/1348842/what-should-i-set-java-home-to-on-osx) – Villat Oct 09 '19 at 17:29
  • Probably your `PATH` is messed up, because `export` execute everytime it's called. My tip is to echo `PATH` (a clean one possibly) to a new env var (like `DEFAULT_PATH`) and then exporting `PATH` in bash_aliases **without** concatenating `PATH` with itself, but joining `DEFAULT_PATH` and `JAVA_HOME` – crissal Oct 09 '19 at 17:32

1 Answers1

0

When I tried to move to /usr/bin/java, I got the reply

N201960-MAC:~ pnutalap$ cd /usr/bin/java -bash: cd: /usr/bin/java: Not a directory

Looks like within /usr/bin/ folder, the 'java' is not a directory, but a symbolic link. Now it makes sense why it is trying to say Unable to locate an executable at "/usr/bin/java/bin/java" simply going by the PATH variable.

PraNuta
  • 629
  • 3
  • 12
  • 33