如何找到在 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
how to find the exact location where java is installed in unix
提问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 which
command gives you the path to the java
binary:
该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 readlink
command in combination with -f
which follows symlinks for you:
然后按照符号链接,直到您到达源头。或者,如果您的系统上可用,请readlink
结合使用-f
以下符号链接的命令:
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 thispage describes how to get greadlink
to 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_HOME
is 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 symlink
through other methods.
say readlink
or 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”命令。
回答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