Find java bin directory

Where can I find the Java SDK in Linux after installing it?

I installed JDK using apt-get install but I don’t know where my jdk folder is. I need to set the path for that. Does any one have a clue on the location?

14 Answers 14

This depends a bit from your package system . if the java command works, you can type readlink -f $(which java) to find the location of the java command. On the OpenSUSE system I’m on now it returns /usr/lib64/jvm/java-1.6.0-openjdk-1.6.0/jre/bin/java (but this is not a system which uses apt-get ).

On Ubuntu, it looks like it is in /usr/lib/jvm/java-6-openjdk/ for OpenJDK, and in some other subdirectory of /usr/lib/jvm/ for Suns JDK (and other implementations as well, I think).

For any given package you can determine what files it installs and where it installs them by querying dpkg. For example for the package ‘openjdk-6-jdk’: dpkg -L openjdk-6-jdk

I think readlink as given is most elegant (and efficient), but I suggest readlink -f $(which javac) — note the ‘c’ in case there is a strange mix of JDK and JRE on the same machine. The JDK includes a compiler (javac) and a JRE does not. However if path is not correct, which will fail and you can try this: find /usr/java -wholename ‘*ava/jdk*’ -prune as I note in a comment below.

will tell you which java implementation is the default for your system and where in the filesystem it is installed. Check the manual for more options.

@dequis, it’s an answer specific to debian, since the question mentioned apt-get and the distro to be Debian 2.6.26 . AFAIK, it should be the same for all debian derivatives.

should give you something like

This does not actually point to a full JDK. 1. It is a symlink, and even if you read the symlink, the binary is also not within a JDK. For example, if I run the command readlink -f $(which javac) it prints /usr/lib/jvm/java-8-oracle/bin/javac . That bin folder is NOT a JDK. General acid-base test to see if its a JDK is to see if the current $JAVA_HOME contains a path of lib/tools.jar . In the cast of /usr/lib/jvm/java-8-oracle/bin that is not true, therefore it is not a JDK.

On Centos / RHL This is what I prefer to find the JDK (if installed) find /usr/java -wholename ‘*ava/jdk*’ -prune But behavior depends whether you are talking about OpenJDK or Oracle Java and how it was installed in the first place.

This question will get moved but you can do the following

«find / -name ‘javac'» is less typing, but requires admin (root) privilege or you will get a lot permission denied messages.

Читайте также:  Numpy python все функции

Use find to located it. It should be under /usr somewhere:

When running the command, if there are too many «Permission denied» message obfuscating the actual found results then, simply redirect stderr to /dev/null

find /usr -name java 2> /dev/null 

Another best way to find Java folder path is to use alternatives command in Fedora Linux (I know its for Ubuntu but I hit this post from google just by its headline). Just want to share incase people like me looking for answers for fedora flavour.

To display all information regarding java

alternatives --display java 

Three Step Process: First: open Terminal-> $ whereis java it would give output like this: java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz

Second: ls -l /usr/bin/java It would give output like this: lrwxrwxrwx 1 root root 22 Feb 9 10:59 /usr/bin/java -> /etc/alternatives/java

Third: ls -l /etc/alternatives/java output is the JDK path: lrwxrwxrwx 1 root root 46 Feb 9 10:59 /etc/alternatives/java -> /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

It’s /usr/local/java/jdk[version]

This question still seems relevant, and the answer seems to be a moving target.

On my debian system (buster):

> update-java-alternatives -l java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64 

However, if you actually go look there, you’ll see there are multiple directories and symbolic links placed there by the package system to simplify future maintenance.

The actual directory is java-11-openjdk-amd64 , with another symlink of default-java . There is also an openjdk-11 directory, but it appears to only contain a source.zip file.

Given this, for Debian ONLY, I would guess the best value to use is /usr/lib/jvm/default-java , as this should always be valid, even if you decide to install a totally different version of java, or even switch vendors.

The normal reason to want to know the path is because some application wants it, and you probably don’t want that app to break because you did an upgrade that changed version numbers.

Источник

How to find path where jdk installed?

I’ve installed jdk1.7.0.rpm package in RHEL6.
Where I do find the path to execute my first java program?

Hi, Mohammad. It’s not a stupid question, but one that has been answered in several places already — like this or this question.

Just an PS: on MacOS, Java is usually installed at ‘/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home’, where the version number could be different.

4 Answers 4

For your first java program read this tutorial:

Note these commands give different results. If you are interested in the non-symlink path use whereis java.

I don’t really think this answers the question. The java binary gets installed with the JRE, but if you’re doing development you need JDK, which isn’t necessarily installed in which java (which in my case is /usr/bin).

On RHEL7, you can use locate :

and it led me to the /usr/lib/jvm/ directory which contained the directories:

java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/ jre/ jre-1.8.0/ jre-1.8.0-openjdk/ jre-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64/ jre-openjdk/ 

Each of these contain a bin/java

Читайте также:  Html scale div height

To find the full path of the symbolic link use:

This gave me mostly JDK6 even though java -version gave me 1.8. There was one link to the JDK8 folder near the top.

You can list the installed files with

You will see somewhere a bin directory with java executable

But if the JDK RPM was correctly installed you should already find java in you path.

javac MyFirstJavaClass.java 

and if everything compiles

(If you didn’t change anything the current directory . should already be in your class path)

Since this question is RPM specific, rpm is the way to get started (as answered by @Matteo).

-q is short for --query -l is short for --list 
rpm -ql jdk1.8.0_20 | grep "jdk1.8.0_20/bin$" 

Knowing this may be desirable for setting a user or application’s $JAVA_HOME variable. This is often needed when a system has multiple versions of java installed, or multiple distributions of java installed, such as OpenJDK and Oracle/Sun.

$JAVA_HOME Example

In the ~/.bash_profile , or related file ( .bashrc , .zshrc , .cshrc , setenv.sh ), something similar to the below may be used.

JAVA_HOME='/usr/java/jdk1.8.0_20' export JAVA_HOME PATH="$JAVA_HOME/bin:$PATH" export PATH 

If you would like more control over where Java gets installed, such as in /opt , then the tarball can be used instead of the RPM file.

Other similar questions, are asking about how to find any binary or file, in the general case.

Источник

How to find where javaw.exe is installed?

So, for a project I am working on, I need to find out where a javaw.exe is located on a user’s machine. How do I do that? Assuming that user is on Windows machine The method that I used is limited to English versions of Windows only.
I looked for where the OS is installed, locate the Program Files directory, locate Java , jdk directory, bin , then javaw.exe . I know this will not work on non-English versions of Windows. What is the human-language-independent way to do this ?

There exist OS-specific search APIs for finding files, and for getting the version from an executable. On Windows, you can use the Windows Search API to search, and ::GetFileVersionInfo(. ) to get the version. Note that the search can take some time to complete. An alternative is to ship your own JVM, making it trivial to find by a relative path.

@LittleChild: Note that you usually won’t find JDK installed on the average user’s PC. Your chances are better looking for a JRE installation.

5 Answers 5

For the sake of completeness, let me mention that there are some places (on a Windows PC) to look for javaw.exe in case it is not found in the path: (Still Reimeus’ suggestion should be your first attempt.)

1.
Java usually stores it’s location in Registry, under the following key:
HKLM\Software\JavaSoft\Java Runtime Environement\\JavaHome

Читайте также:  Python events and handlers

2.
Newer versions of JRE/JDK, seem to also place a copy of javaw.exe in ‘C:\Windows\System32’, so one might want to check there too (although chances are, if it is there, it will be found in the path as well).

3.
Of course there are the «usual» install locations:

  • ‘C:\Program Files\Java\jre*\bin’
  • ‘C:\Program Files\Java\jdk*\bin’
  • ‘C:\Program Files (x86)\Java\jre*\bin’
  • ‘C:\Program Files (x86)\Java\jdk*\bin’
[Note, that for older versions of Windows (XP, Vista(?)), this will only help on english versions of the OS. Fortunately, on later version of Windows «Program Files» will point to the directory regardless of its «display name» (which is language-specific).]

A little while back, I wrote this piece of code to check for javaw.exe in the aforementioned places. Maybe someone finds it useful:

static protected String findJavaw() < Path pathToJavaw = null; Path temp; /* Check in Registry: HKLM\Software\JavaSoft\Java Runtime Environement\\JavaHome */ String keyNode = "HKLM\\Software\\JavaSoft\\Java Runtime Environment"; List output = new ArrayList<>(); executeCommand(new String[] , output); Pattern pattern = Pattern.compile("\\s*CurrentVersion\\s+\\S+\\s+(.*)$"); for (String line : output) < Matcher matcher = pattern.matcher(line); if (matcher.find()) < keyNode += "\\" + matcher.group(1); Listoutput2 = new ArrayList<>(); executeCommand( new String[] , output2); Pattern pattern2 = Pattern.compile("\\s*JavaHome\\s+\\S+\\s+(.*)$"); for (String line2 : output2) < Matcher matcher2 = pattern2.matcher(line2); if (matcher2.find()) < pathToJavaw = Paths.get(matcher2.group(1), "bin", "javaw.exe"); break; >> break; > > try < if (Files.exists(pathToJavaw)) < return pathToJavaw.toString(); >> catch (Exception ignored) <> /* Check in 'C:\Windows\System32' */ pathToJavaw = Paths.get("C:\\Windows\\System32\\javaw.exe"); try < if (Files.exists(pathToJavaw)) < return pathToJavaw.toString(); >> catch (Exception ignored) <> /* Check in 'C:\Program Files\Java\jre*' */ pathToJavaw = null; temp = Paths.get("C:\\Program Files\\Java"); if (Files.exists(temp)) < try (DirectoryStreamdirStream = Files.newDirectoryStream(temp, "jre*")) < for (Path path : dirStream) < temp = Paths.get(path.toString(), "bin", "javaw.exe"); if (Files.exists(temp)) < pathToJavaw = temp; // Don't "break", in order to find the latest JRE version >> if (pathToJavaw != null) < return pathToJavaw.toString(); >> catch (Exception ignored) <> > /* Check in 'C:\Program Files (x86)\Java\jre*' */ pathToJavaw = null; temp = Paths.get("C:\\Program Files (x86)\\Java"); if (Files.exists(temp)) < try (DirectoryStreamdirStream = Files.newDirectoryStream(temp, "jre*")) < for (Path path : dirStream) < temp = Paths.get(path.toString(), "bin", "javaw.exe"); if (Files.exists(temp)) < pathToJavaw = temp; // Don't "break", in order to find the latest JRE version >> if (pathToJavaw != null) < return pathToJavaw.toString(); >> catch (Exception ignored) <> > /* Check in 'C:\Program Files\Java\jdk*' */ pathToJavaw = null; temp = Paths.get("C:\\Program Files\\Java"); if (Files.exists(temp)) < try (DirectoryStreamdirStream = Files.newDirectoryStream(temp, "jdk*")) < for (Path path : dirStream) < temp = Paths.get(path.toString(), "jre", "bin", "javaw.exe"); if (Files.exists(temp)) < pathToJavaw = temp; // Don't "break", in order to find the latest JDK version >> if (pathToJavaw != null) < return pathToJavaw.toString(); >> catch (Exception ignored) <> > /* Check in 'C:\Program Files (x86)\Java\jdk*' */ pathToJavaw = null; temp = Paths.get("C:\\Program Files (x86)\\Java"); if (Files.exists(temp)) < try (DirectoryStreamdirStream = Files.newDirectoryStream(temp, "jdk*")) < for (Path path : dirStream) < temp = Paths.get(path.toString(), "jre", "bin", "javaw.exe"); if (Files.exists(temp)) < pathToJavaw = temp; // Don't "break", in order to find the latest JDK version >> if (pathToJavaw != null) < return pathToJavaw.toString(); >> catch (Exception ignored) <> > return "javaw.exe"; // Let's just hope it is in the path :) > 

Источник

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