Reputation: 125
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
Upvotes: 1
Views: 2716
Reputation: 307
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
Upvotes: 3