简体   繁体   中英

how to find the exact location where java is installed in unix

I am using SSH Client. I have run the environment variable still

echo $JAVA_HOME is not returning anything. I want to find the exact location where the java is installed in unix. is there any other command which can help me with this ?

The which command gives you the path to the java binary:

which java

But if it is only a symlink (eg used by alternatives ) this will not get your the real path to the binary. You can either list where the symlink points to with with ls -l :

ls -l `which java`

which for me outputs

/usr/bin/java -> /etc/alternatives/java

and then follow the symlinks until you are at the source. Alternatively, if available on your system, use the readlink command in combination with -f which follows symlinks for you:

readlink -f `which java`

Edit: Ankit wrote in the comments that readlink is not a standard UNIX command and -f also does not seem to work on a mac, so this may not be an option for you, although this page describes how to get greadlink to get this functionality on a mac via brew :

brew install coreutils greadlink -f which java

since echo $JAVA_HOME is not giving you the path, this variable is probably not already set. Instead, which command would give you the path.

which java

Note that, this might not give you the exact location if command is a symlink . If that is the case, you must resolve the symlink through other methods. say readlink or through python (os.path.realpath(path))

Can you run ? whereis java

As far as I remmember it gives symbolic link to location.

On Unix you should be able to use the 'which java' command.

https://en.wikipedia.org/wiki/Which_(Unix)

您可以尝试使用这两个命令

$ which java

$ whereis java

Try this

$ which java

might result output as

/usr/bin/java

You can very easily find the Java Home Directory by appending /jre to the output directory of the below command

sudo update-java-alternatives -l

Sample output will be

java-11-oracle                 1091       /usr/lib/jvm/java-11-oracle

Now append /jre which makes the JAVA HOME as

/usr/lib/jvm/java-11-oracle/jre

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM