Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is path of JDK on Mac ? [duplicate]

Tags:

java

macos

Im using Mac only at work and I need to set JAVA_HOME to proper path of JDK. I downloaded JDK, installed it and now I can't find it anywhere. I was looking at the internet for the solution, but there is no folder Libraries/Java.

like image 705
filipp.kowalski Avatar asked Aug 09 '13 10:08

filipp.kowalski


People also ask

Where is JDK folder located?

The JDK software is installed on your computer, for example, at C:\Program Files\Java\jdk1.

What is a JDK path?

The path is the most important environment variable of the Java environment which is used to locate the JDK packages that are used to convert the java source code into the machine-readable binary format. Tools like javac and java can be used by setting the path.


2 Answers

The location has changed from Java 6 (provided by Apple) to Java 7 and onwards (provided by Oracle). The best generic way to find this out is to run

/usr/libexec/java_home 

This is the natively supported way to find out both the path to the default Java installation as well as all alternative ones present.

If you check out its help text (java_home -h), you'll see that you can use this command to reliably start a Java program on OS X (java_home --exec ...), with the ability to explicitly specify the desired Java version and architecture, or even request the user to install it if missing.

A more pedestrian approach, but one which will help you trace specifically which Java installation the command java resolves into, goes like this:

  1. run

    which java 
  2. if that gives you something like /usr/bin/java, which is a symbolic link to the real location, run

    ls -l `which java` 

    On my system, this outputs

    /usr/bin/java -> /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/bin/java 

    and therefrom you can read the Java home directory;

  3. if usr/bin/java points to another symbolic link, recursively apply the same approach with

    ls -l <whatever the /usr/bin/java symlink points to> 

An important variation is the setup you get if you start by installing Apple's Java and later install Oracle's. In that case Step 2 above will give you

/usr/bin/java -> /System/Library/Frameworks/JavaVM.framework/Commands/java 

and that particular java binary is a stub which will resolve the actual java command to call by consulting the JAVA_HOME environment variable and, if it's not set or doesn't point to a Java home directory, will fall back to calling java_home. It is important to have this in mind when debugging your setup.

like image 166
Marko Topolnik Avatar answered Sep 27 '22 22:09

Marko Topolnik


Which Mac version are you using? try these paths

 /System/Library/Frameworks/JavaVM.framework/ OR  /usr/libexec/java_home 

This link might help - How To Set $JAVA_HOME Environment Variable On Mac OS X

like image 25
Chetan Gole Avatar answered Sep 27 '22 23:09

Chetan Gole