1

In bash_profile the java_home is set as given below

export JAVA_HOME=$(/usr/libexec/java_home)

command "echo $JAVA_HOME" gives the below path

/Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home

command "which java" gives the below path

/usr/bin/java

command Whereis java give the below path

/usr/bin/java

command "ls -la /usr/bin/java" gives the below link

lrwxr-xr-x 1 root wheel 74 Jan 15 2019 /usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

Why is that the java_home is different from the paths returned by "which java" and "Whereis java". Also why is /usr/bin/java linked to java in another location

1
  • It's probably because JAVA_HOME hasn't been set correctly during installation Commented May 8, 2020 at 18:49

1 Answer 1

3

Why is that the java_home is different from the paths returned by "which java" and "Whereis java". Also why is /usr/bin/java linked to java in another location

JAVA_HOME is an environment variable

Any command run on shell / command prompt would be looked up in $PATH

by default "/usr/bin/*" is in PATH

To get your java and javac in PATH you will need to use following

export PATH=$JAVA_HOME/bin:$PATH

This when put in your bashrc or bash_profile will always use java and its related executable binaries from your JAVA_HOME. Remember to put this before the existing path as shown above.

Hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

"Remember to put this before the existing path as shown above" . this worked !! Thanks A G

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.