Search code examples
javamacosmacos-high-sierrajava-homehomebrew-cask

Multiple Java Executables on New Machine


TLDR; Why does brew/cask (or maybe even the native installer) install multiple executables for java?

System Data:

MacOS 10.13 / High Sierra

I am setting up a new dev machine and before installing java ran the following command: java and was told that no binary could be found.

From here I ran brew cask install java. At this point java became executable and running which java provided me a path at usr/bin/java. This location unsurprisingly turns out to be a link to

/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java

Out of curiosity I ran: /usr/libexec/java_home which returned:

/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home

I believe that is the typical location for the JAVA_HOME environment variable. However, when looking at the path which the java bin points to you will notice that the location are different. JAVA_HOME/bin points to a location in /Library while which java points to a location in System/Library I understand that there is a general rule in Mac computing that says that /System resources are basic machine settings that shouldn't be monkeyed with and that /Library resources are for user installed and managed software, but I do not understand why I would have the exact same executable stored in two places.

My question is, why is the same software installed at two different places and why would JAVA_HOME/bin point to one binary while which java would point to another?


Resources I Used Before Asking:

what does mac os /Library folder store?

Where is Oracle's (Sun's) JDK/JRE installed on Mac OS X 10.8 Mountain Lion?


Solution

  • This question is a duplicate and the answer comes from user bdash who deserves all credit for answering in a full and clear manner. Thanks to Naveen Kumar who provided this pointer. For full answer go to:

    Understanding Oracle's Java on Mac

    The short answer for folks coming to this page from google is that the items in /System/Library are stubs and not the real java executable. The true location for the JDK is the one exposed by /usr/libexec/java_home.