882

I downloaded Java 7u17 on Mac OS 10.7.5 from here and successfully installed it. To do some JNI programming, I need to know where Java is installed on my Mac.

I thought that inside the /Library/Java/JavaVirtualMachines/ folder, there would be a folder called 1.7.0.jdk or something, but then I found the folder empty. This was confirmed by running ls /Library/Java/JavaVirtualMachines/ in the Terminal. I've tried searching for it to find out if it was installed somewhere, but that doesn't seem to be turning anything up.

Could someone please tell me where Java is installed on my Mac?

2

21 Answers 21

1656

Use /usr/libexec/java_home -v 1.8 command on a terminal shell to figure out where is your Java 1.8 home directory

If you just want to find out the home directory of your most recent version of Java, omit the version. e.g. /usr/libexec/java_home

6
  • 1
    I got to this question because I was getting an error in eclipse on my mac because I was getting an error on the first line of the program "import java.util.*." I strongly suspect this is because the java path isn't set correctly or something (even though I set this up once before). I entered the command in this answer and I get a directory. Can I just paste that directory into the textbox in the "Native library folder config" window? Or does this directory belong somewhere else? Commented Apr 16, 2015 at 20:40
  • 60
    Added export JAVA_HOME=`/usr/libexec/java_home` to .bash_profile so JAVA_HOME is always set (note the back-ticks around the libexec command) Commented Nov 17, 2015 at 0:33
  • 2
    If you just want to know if the JDK is installed on your mac, omit the version number and run from terminal: $ echo $(/usr/libexec/java_home) Commented Mar 24, 2018 at 21:41
  • 6
    On Mac 10.12.3, we should /usr/libexec/java_home -- v to show the most recent version of java
    – klion26
    Commented Jan 7, 2019 at 3:49
  • 4
    Note that macOS Big Sur changed the behaviour of the java_home command. Noe, if if the JAVA_HOME environment variable is already set to a valid JDK that is all it will return, it will ignore the -v parameter. If JAVA_HOME is set to an invalid folder, the java_home command won't work at all. To get a reasonable output you must unset JAVA_HOME before invoking /usr/libexec/java_home
    – swpalmer
    Commented Nov 18, 2020 at 16:19
193

You could use

/usr/libexec/java_home

command in your terminal to know the path where Java being installed.

7
  • 9
    I like this solution better than the accepted answer because it is independent of the version of the JVM installed. Commented Feb 25, 2016 at 20:52
  • 1
    This didn't find my java 8 version installed by Oracle. Commented Apr 28, 2016 at 22:05
  • 18
    Why do you have the echo $(...) there? Doesn't just /usr/libexec/java_home do the same? Commented May 10, 2016 at 9:04
  • 1
    The accepted answer did not work for me but this worked! (I'm normally not a mac/unix user)
    – Roel
    Commented Jul 22, 2016 at 15:36
  • @PaŭloEbermann It doesn't work for me without dolar sign and brackets. Commented Mar 23, 2017 at 21:14
87

Turns out that I actually had the Java 7 JRE installed, not the JDK. The correct download link is here. After installing it, jdk1.7.0jdk appears in the JavaVirtualMachines directory.

2
  • 57
    For me, it was under /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk (knowing that for the JDK 1.6 the path is : /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/)
    – Zakaria
    Commented Jul 9, 2014 at 19:56
  • 3
    export JAVA_HOME=$(/usr/libexec/java_home) at ~/.bash_profile Commented Jul 21, 2019 at 14:43
47

If you install just the JRE, it seems to be put at:

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
7
  • 3
    You should not rely on this existing. If you need the JRE, bundle inside your own application.
    – swingler
    Commented Feb 6, 2014 at 19:49
  • 1
    Setting JAVA_HOME with a path containing a space character is challenging ! I didn't succeeded... Commented Jun 30, 2014 at 16:02
  • you can create somewhere a link to this directory and set JAVA_HOME to that link
    – Kuba
    Commented Aug 27, 2014 at 18:33
  • This is where the "Java" System Preferences panel seems to install it. Commented Mar 21, 2016 at 14:31
  • 3
    @AntoineRosset, you can set it this way: export JAVA_HOME=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    – coda
    Commented May 6, 2016 at 22:35
41

Try This, It's easy way to find java installed path in Mac OS X,

GoTO

1 ) /Library i.e Macintosh HD/Library

enter image description here

2) Click on Library in that we find Java folder.

enter image description here

3) So final path is

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

Hope so this is help for someone .

3
  • 2
    Pretty helpful when you have to point the JDK explicitly from an IDE. Thanks Commented Nov 30, 2018 at 5:59
  • 1
    How Dense am I? My terminal says that I have 2 jdk's installed in /Library/Java/JavaVirtualMachines/ but I can't find them when I navigate to that directory in finder... How dense can I get... Commented Dec 13, 2018 at 4:43
  • @SoftwareSavant, Please ref stackoverflow.com/a/14875241 answer ,It's may be help you . Commented Dec 13, 2018 at 6:03
38

Use unix find function to find javas installed...

sudo find / -name java
6
  • 26
    You do not need sudo to run find for generally-accessible commands. If you don't want to see the error messages about inaccessible directories, get rid of the messages rather than using root privs unnecessarily. Using sudo all the time is a bad habit. Redirect stderr to /dev/null, like this: find / -name java 2> /dev/null Commented Sep 26, 2013 at 15:29
  • 1
    What should i do if i need too look under inaccessible directories ?
    – serkan
    Commented Sep 29, 2013 at 11:29
  • 2
    Walter's point is that the java binary will be world readable, therefore sudo is not necessary. Your answer is still useful :)
    – Jared Beck
    Commented Nov 6, 2013 at 16:32
  • Yes, I just used this to find src.zip (the source code of the java jdk)
    – Dinis Cruz
    Commented Jan 22, 2014 at 11:44
  • export JAVA_HOME=$(/usr/libexec/java_home) at ~/.bash_profile Commented Jul 21, 2019 at 14:43
25

If you type

java -verbose 

This also gives the location from which the jars are loaded and hence also the java path.

1
  • 1
    I added export JAVA_HOME=$(/usr/libexec/java_home) at ~/.bash_profile. Commented Jul 21, 2019 at 14:44
23

Java package structure of Mac OS is a bit different from Windows. Don't be upset for this as a developer just needs to set PATH and JAVA_HOME.

So in .bash_profile set JAVA_HOME and PATH as below. This example is for Java 6:

export JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
export PATH=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin:$PATH
2
  • 12
    This removes about everything else from the path? Do this only if you are only using Java and nothing else in your system. Commented May 10, 2016 at 9:05
  • export JAVA_HOME=$(/usr/libexec/java_home) at ~/.bash_profile. Commented Jul 21, 2019 at 14:44
23

You may not realize it, but you likely have multiple Java versions installed.

To list the version, architecture, and folder location of all installed JVMs on your Mac:

$ /usr/libexec/java_home --verbose

Or:

$ /usr/libexec/java_home -V (That's an uppercase V!)

Sample output:

$ /usr/libexec/java_home -V
Matching Java Virtual Machines (4):
    12.0.1 (x86_64) "Oracle Corporation" - "Java SE 12.0.1" /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home
    1.8.202.08 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_282 (x86_64) "Amazon" - "Amazon Corretto 8" /Users/username/Library/Java/JavaVirtualMachines/corretto-1.8.0_282/Contents/Home
    1.8.0_202 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
/Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home
1
  • 1
    This is a more complete answer IMHO. I had multiple versions installed and the /Internet Plug-Ins/... was causing an issue with the Java updater tool, but I couldn't find the version the tool was complaining about ... until now.
    – wildcat12
    Commented Sep 21, 2022 at 22:19
12

just write /Library/Java/JavaVirtualMachines/
in Go to Folder --> Go in Finder

3
  • ok, I just tried this and I managed to navigate to the directory. Why can't I navigate to that folder normally in Finder? Is this just Apple being extra annoying... Also extra annoying, Gradle version 4.3 doesn't work with any version of Java except for Java 8 Commented Dec 13, 2018 at 4:48
  • export JAVA_HOME=$(/usr/libexec/java_home) at ~/.bash_profile Commented Jul 21, 2019 at 14:44
  • this folder is empty in my case ... but when i check java -version ... it show version 1.8 Commented Oct 1, 2022 at 14:58
12

type which java in terminal to show where it is installed.

1
  • 2
    Yes, export JAVA_HOME=$(/usr/libexec/java_home) at ~/.bash_profile. Commented Jul 21, 2019 at 14:45
10

Edited: Alias to current java version is /Library/Java/Home

For more information: a link

3
  • That would be an alias for the most recent version, which would correctly point to Java 7 SDK once it is installed. Commented Apr 5, 2013 at 5:12
  • 2
    This link only exists for legacy purposes, and will not be updated by installing Java 7. Do not use this path.
    – swingler
    Commented Feb 6, 2014 at 19:50
  • I updated export JAVA_HOME=$(/usr/libexec/java_home) at ~/.bash_profile. Commented Jul 21, 2019 at 14:44
8

For :

  • OS X : 10.11.6

  • Java : 8

I confirm the answer of @Morrie .

   export JAVA_HOME=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home;

But if you are running containers your life will be easier

3
  • 2
    I think this should have been a comment. Commented Sep 19, 2016 at 1:15
  • 1
    I dont think , because there is an Added value which is ` export JAVA_HOME=`. ... What about you @Thunderforge Commented Sep 19, 2016 at 1:32
  • export JAVA_HOME=$(/usr/libexec/java_home) at ~/.bash_profile. Commented Jul 21, 2019 at 14:46
7

I have just installed the JDK for version 21 of Java SE 7 and found that it is installed in a different directory from Apple's Java 6. It is in /Library/Java... rather then in /System/Library/Java.... Running /usr/libexec/java_home -v 1.7 versus -v 1.6 will confirm this.

1
  • 1
    export JAVA_HOME=$(/usr/libexec/java_home) at ~/.bash_profile Commented Jul 21, 2019 at 14:45
7

I tried serkan's solution, it found java 7's location on OS X Mavericks. it is resided in "/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/" but to make it the default JDK I had to set JAVA_HOME system variable in .bash_profile in home directory to "/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/" so its up and running now thanks to serkan's idea

1
  • export JAVA_HOME=$(/usr/libexec/java_home) at ~/.bash_profile. Commented Jul 21, 2019 at 14:45
5

Try to check in here
/Library/Java/JavaVirtualMachines

2

if you are using sdkman

you can check it with sdk home java <installed_java_version>

$  sdk home java 8.0.252.j9-adpt
/Users/admin/.sdkman/candidates/java/8.0.252.j9-adpt

you can get your installed java version with

$ sdk list java
2

If it's installed via IntelliJ IDEA. It's at ~/Library/Java/JavaVirtualMachines

1

Simply enter the following in your terminal :

whereis java
0
0

The System Preferences then Java control panel then Java then View will show the exact location of the currently installed default JRE.

1
  • 1
    export JAVA_HOME=$(/usr/libexec/java_home) at ~/.bash_profile Commented Jul 21, 2019 at 14:45
0

MacOS BigSur

Add following under .zshrc file. If .zshrc is not present, create and add.

export JAVA_HOME=`/usr/libexec/java_home`

Not the answer you're looking for? Browse other questions tagged or ask your own question.