Find java installation location

Where is Java Installed on Mac OS X?

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?

To close voters/reopeners — this question is explicitly not off-topic (questions about tools commonly used by programmers). Unfortunately, it got bandwagoned by meta.

I found the JDK in /Library/Java/JavaVirtualMachines/. I’m using macOS Big Sur(11.0.1). And installed jdk version is 1.8.0

20 Answers 20

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

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?

Читайте также:  Example

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)

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)

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

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

I like this solution better than the accepted answer because it is independent of the version of the JVM installed.

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.

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/ )

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

/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home 

@AntoineRosset, you can set it this way: export JAVA_HOME=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

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

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 .

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.

Use unix find function to find javas installed.

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

Walter’s point is that the java binary will be world readable, therefore sudo is not necessary. Your answer is still useful 🙂

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

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 

This removes about everything else from the path? Do this only if you are only using Java and nothing else in your system.

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 -V (That’s an uppercase V!)

$ /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 

Источник

How to find path to java?

That tells the command java resides in /usr/bin/java.

$ ls -l /usr/bin/java lrwxrwxrwx 1 root root 22 2009-01-15 18:34 /usr/bin/java -> /etc/alternatives/java 

So, now we know that /usr/bin/java is actually a symbolic link to /etc/alternatives/java .

Dig deeper using the same method above:

$ ls -l /etc/alternatives/java lrwxrwxrwx 1 root root 31 2009-01-15 18:34 /etc/alternatives/java -> /usr/local/jre1.6.0_07/bin/java 

So, thats the actual location of java: /usr/local/jre.

You could still dig deeper to find other symbolic links.

export JAVA_HOME=$(dirname $(dirname $(update-alternatives --list javac))) 

To make this seemingly over done setting clearer, on my Ubuntu linux machine with open JDK 8 installed:

$ update-alternatives --list java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java $ update-alternatives --list javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 

but what we need is the path to the directory containing bin of the JDK. So ask for the location of javac and then use dirname twice.

See man update-alternatives for more.

Be aware of the possibility that people might have two JDK’s installed. To always use the first one as your JAVA_HOME you can use head : JAVA_HOME=$(dirname $(dirname $(update-alternatives —list javac 2>&1 | head -n 1)))

Starting from January 2019, the licensing model for Oracle Java has changed. PPAs such as ‘ppa:webupd8team/java’ used in many Java installation tutorials now become unavailable.

Here I would like to share how I installed Java 8 on Ubuntu 16.04, and set the Java path in terminal.

Installation

I followed the instruction on the official documentation to install Java with .tar.gz

Path setting

The instruction is also from the official documentations. The steps to set up Java path are much simpler here.

After performing all the steps, restart the terminal and run ‘java -version’ to verify installation.

Источник

JAVA_HOME : where is java installed

I’m trying to set the JAVA_HOME to get tomcat 7 to work with no success. I’m using CentOS 6.3. Here is what I did so far: which java /usr/bin/java so I edited the .bash_profile, I added export JAVA_HOME=/usr/bin/java didn’t work. I searched online and found another user on stackoverflow who found it in /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/java I searched on my computer and found that java is located in /usr/lib/jvm/jre-1.6.0-openjdk/bin I then changed the JAVA_HOME to export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk/bin , tried to start tomcat but server can’t be found. How do I find where java was installed? I didn’t install it myself; it was installed during linux installation. Thanks in advance, Mike

JAVA_HOME is the directory that contains the bin directory, in this case /usr/lib/jvm/jre-1.6.0-openjdk .

I cd into the directory that tomcat was extracted to, then I type bin/startup.sh I was told to start 2 terminals. Type tail -f /server/apache-tomcat-7.0.33/logs/catalina.out in the first one then move the second terminal and type bin/startup.sh I got this /server/apache-tomcat-7.0.33/logs/catalina.sh : line 389 : /usr/bin/java/bin/java : Not a directory I changed JAVA_HOME to export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk, it didn’t work

3 Answers 3

export JAVA_HOME=/usr should do it. The script runs $JAVA_HOME/bin/java

Thank you! It finally worked but now I have another problem if I type localhost.com:8080 , I get server not found. If I type 127.0.0.1:8080 , the Apache software foundation page displays. This computer isn’t connected to the internet.

that won’t work then. localhost.com is not your machine, it’s a real domain. You probably want to access localhost:8080

Just out of curiosity, if i want it to work locally will all I need to do is set up a dns? I don’t care if it’s localhost.com or anything else. I’m just curious as to how the setup of .com domain will work.

The strictly correct answer is this:

export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk 

The issue is that on a typical Linux system you access the java command (etc) via symbolic links that are created / managed by the alternatives command. This allows you to make a system-wide choice over which of the java installations should be used by default; i.e. via commands in /usr/bin .

The second issue this that the JAVA_HOME environment variable should point at the Java installation directory. The «bin» directory is a subdirectory of the installation directory. (Look at the contents of «/usr/lib/jvm/jre-1.6.0-openjdk» !!)

While export JAVA_HOME=/usr/bin will work for locating the commands, it won’t work if the Java application needs to find other files in the installation; e.g. the «rt.jar» file.

This «fine distinction» possibly doesn’t matter for Tomcat, but it is likely to matter for other Java software that uses the JAVA_HOME convention.

Footnote: if you are using an Oracle Java for Linux installation, the default installation directory will be a subdirectory «/usr/java». Sadly, the Oracle installer doesn’t understand that Linux «alternatives» system. You either have to register the alternatives for each of the Java commands by hand (tedious!!) or add the installation’s «bin» directory to your PATH.

Источник

How to determine Windows Java installation location

I’m trying to dynamically run a .jar from a C# assembly (using Process.Start(info) ). Now, from a console application I am able to just run:

ProcessStartInfo info = new ProcessStartInfo("java", "-jar somerandom.jar"); 

In an assembly, however, I keep getting a Win32Exception of «The system cannot find the file specified» and have to change the line to the full path of Java like so:

ProcessStartInfo info = new ProcessStartInfo("C:\\Program Files\\Java\\jre6\\bin\\java.exe", "-jar somerandom.jar"); 

This obviously won’t do. I need a way to dynamically (but declaratively) determine the installed location of Java. I started thinking of looking to the registry, but when I got there I noticed that there were specific keys for the versions and that they could not even be guaranteed to be numeric (e.g. «HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.6» and «HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.6.0_20»). What would be the most reliable «long-haul» solution to finding the most up-to-date java.exe path from a C# application? Thanks much in advance. — EDIT — Thanks to a combination of GenericTypeTea’s and Stephen Cleary’s answers, I have solved the issue with the following:

private String GetJavaInstallationPath() < String javaKey = "SOFTWARE\\JavaSoft\\Java Runtime Environment"; using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(javaKey)) < String currentVersion = baseKey.GetValue("CurrentVersion").ToString(); using (var homeKey = baseKey.OpenSubKey(currentVersion)) return homeKey.GetValue("JavaHome").ToString(); >> 

Источник

Оцените статью