我尝试改变环境,但没有成功。
我认为我写错了 Java 的路径。我这样写/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
。
我如何才能找到真正的 Java 路径?
答案1
我已经安装了 Java 1.7,正如我从java -version
如果您想知道某些执行的命令位于何处 - 使用which
命令。
$ which java
/usr/bin/java
引自 man 的话:
DESCRIPTION
which returns the pathnames of the files (or links) which would be exe‐
cuted in the current environment, had its arguments been given as com‐
mands in a strictly POSIX-conformant shell. It does this by searching
the PATH for executable files matching the names of the arguments. It
does not follow symbolic links.
但通常/usr/bin/java
是符号链接,因此要识别 java 二进制文件的实际位置,请使用namei
命令。
$ namei /usr/bin/java
f: /usr/bin/java
d /
d usr
d bin
l java -> /etc/alternatives/java
d /
d etc
d alternatives
l java -> /usr/lib/jvm/java-8-oracle/jre/bin/java
d /
d usr
d lib
d jvm
d java-8-oracle
d jre
d bin
- java
如您所见,在我的例子中,我的java
命令链接到/usr/lib/jvm/java-8-oracle/jre/bin/java
。Java 本身位于/usr/lib/jvm/java-8-oracle
。因此 JAVA_HOME 变量应如下所示:
JAVA_HOME=/usr/lib/jvm/java-8-oracle
如果你按照这些步骤操作,你就能找到你的 JAVA_HOME,我敢打赌/usr/lib/jvm/java-7-openjdk-amd64
答案2
输入此命令:update-alternatives --display java
例如在我的系统上它显示:
java - manual mode
link currently points to /opt/java6/bin/java
/opt/java6/bin/java - priority 1
/opt/java7/bin/java - priority 2
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1071
slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
Current 'best' version is '/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java'.
如果你看一下第二行,它会告诉我我的默认 JDK 的路径