如何找到在 unix 中安装 java 的确切位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40236479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 05:01:23  来源:igfitidea点击:

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

javaunix

提问by divya.trehan573

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

我正在使用 SSH 客户端。我仍然运行了环境变量

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 ?

echo $JAVA_HOME 没有返回任何内容。我想找到在 unix 中安装 java 的确切位置。有没有其他命令可以帮助我解决这个问题?

回答by dudel

The whichcommand gives you the path to the javabinary:

which命令为您提供java二进制文件的路径:

which java

But if it is only a symlink (e.g. 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:

但是如果它只是一个符号链接(例如被使用alternatives),这将无法获得二进制文件的真实路径。您可以使用 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 readlinkcommand in combination with -fwhich follows symlinks for you:

然后按照符号链接,直到您到达源头。或者,如果您的系统上可用,请readlink结合使用-f以下符号链接的命令:

readlink -f `which java`

Edit: Ankit wrote in the comments that readlinkis not a standard UNIX command and -falso does not seem to work on a mac, so this may not be an option for you, although thispage describes how to get greadlinkto get this functionality on a mac via brew:

编辑:Ankit 在评论中写道,这readlink不是标准的 UNIX 命令,-f而且似乎也不适用于 mac,因此这可能不是您的选择,尽管页面描述了如何greadlink在 mac 上通过brew

brew install coreutils greadlink -f which java

brew install coreutils greadlink -f which java

回答by Ankit

since echo $JAVA_HOMEis not giving you the path, this variable is probably not already set. Instead, whichcommand would give you the path.

因为echo $JAVA_HOME没有给你路径,这个变量可能还没有设置。相反,哪个命令会给你路径。

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 symlinkthrough other methods. say readlinkor through python (os.path.realpath(path))

请注意,如果命令是symlink. 如果是这种情况,则必须symlink通过其他方法解决。说readlink或通过python(os.path.realpath(path))

回答by Patryk Rogosch

Can you run ? whereis java

你能跑吗 ? whereis java

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

据我所知,它提供了指向位置的符号链接。

回答by Cédric O.

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

在 Unix 上,您应该能够使用“which java”命令。

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

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

回答by Sid

You can try with these 2 commands

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

$ which java

$ which java

$ whereis java

$ whereis java

回答by Kedar1442

Try this

试试这个

$ which java

$ which java

might result output as

可能导致输出为

/usr/bin/java

/usr/bin/java