Find java home in linux

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.

Читайте также:  Install setup tool linux

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.

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 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 .

Читайте также:  Каким процессом открыт файл linux

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.

Источник

Find JAVA_HOME and set it on RHEL

I had installed java a while ago on my RHEL machine. Now, I’m trying to run a program that requires the JAVA_HOME variable to be set. What is the best way to figure out the installation directory of my java installation and then set JAVA_HOME ? Here are the results of running java- version :

java version "1.7.0_25" Java(TM) SE Runtime Environment (build 1.7.0_25-b15) Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode) 

7 Answers 7

RHEL uses alternatives subsystem to manage java installations. You can have multiple versions of java installed, but only one is active at a time.

This means that running which java doesn’t provide useful information. The output would be the same no matter which java installation is selected via alternatives. Running readlink -f $(which java) (as already suggested in other comment) or using asking alternatives alternatives —display java would be better.

Читайте также:  Get time in linux command

See example from RHEL 6 machine with OpenJDK installed (which is shipped with RHEL):

[root@example ~]# which java /usr/bin/java [root@example ~]# readlink -f $(which java) /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/jre/bin/java [root@example ~]# alternatives --display java | head -2 java - status is manual. link currently points to /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java 

Note that enviroment variable JAVA_HOME is not defined anywhere by default, you would need to define it yourself in .bashrc of user which requires it.

In previous example, correct value of JAVA_HOME would be /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64 .

See details in Install OpenJDK documentation, search for section «Optional: Set the JAVA_HOME environment variable».

Источник

How to find my current JAVA_HOME in ubuntu?

To display JAVA_HOME variable path, type in terminal:

If nothing appears then set it with this:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 

This will differ according to your JDK type and version.

For displaying it again, follow the first command.

Follow JREs from different vendors on the same system, for using different JDK’s or switch between JDK’s.

It gives «/usr/lib/jvm/java-6-sun». But I have installed java 7. When I check it using «java -version» it gives java version «1.7.0_45» Java(TM) SE Runtime Environment (build 1.7.0_45-b18) Java HotSpot(TM) Server VM (build 24.45-b08, mixed mode)

then execute second command for setting JAVA_HOME variable. NOTE: JAVA_HOME doesn’t make jdk default, it just makes JAVA_HOME variable set to a path & if you want to use different jdk installed on same machine then check my answer, I have edited it.

@Jax-L But now when I give echo JAVA_HOME it just displays as «JAVA_HOME». The path I gave is not displaying.

export works only until you restart. Or you add export to the .bashrc login script. But the correct way to set such environment variables is in /etc/environment

If you have JDK 1.6 (corresponding to Java 6) or a newer version installed, you should have a program named jrunscript in your PATH . You can use this to find the corresponding JAVA_HOME . Example:

$ jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));' /opt/local/jdk1.7.0_76/jre 

You could set the environment variable like this:

$ export JAVA_HOME="$(jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));')" 

Note that the JRE doesn’t include jrunscript , so this will only work if you install the JDK, not just the JRE.

Источник

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