java不能在linux下工作。为什么?

时间:2016-10-29 19:10:44

标签: java linux java-home

目前致力于Linux Cinnamon。我从本地驱动器中取消了Open JDK。然后我通过终端检查java -version并给出 -

$ java -version
The program 'java' can be found in the following packages:
 * default-jre
 * gcj-5-jre-headless
 * openjdk-8-jre-headless
 * gcj-4.8-jre-headless
 * gcj-4.9-jre-headless
 * openjdk-9-jre-headless
Try: sudo apt install <selected package>

之后按照安装指南安装oracle jdk 8 linux。然后我刚刚检查了java -version命令[我只是解压jdk/opt/java] -

$ /opt/java/jdk1.8.0_112/bin/java -version
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

我之后使用nano将我的环境变量JAVA_HOME="/opt/java/jdk1.8.0_112" [不包括bin]设置为/etc/environment from JAVA_HOME setup tutorial -

# Java Home
JAVA_HOME="/opt/java/jdk1.8.0_112"
export JAVA_HOME

并刷新&amp;检查了我的JAVA_HOME,如下所示 -

$ echo $JAVA_HOME
/opt/java/jdk1.8.0_112

在我尝试通过命令检查java -version进行这些设置后,它会给出 -

$ java -version
The program 'java' can be found in the following packages:
 * default-jre
 * gcj-5-jre-headless
 * openjdk-8-jre-headless
 * gcj-4.8-jre-headless
 * gcj-4.9-jre-headless
 * openjdk-9-jre-headless
Try: sudo apt install <selected package>

有谁能告诉我发生了什么事?

1 个答案:

答案 0 :(得分:6)

即使您设置$JAVA_HOME,仍然需要将bin添加到$PATH

export PATH="$PATH:$JAVA_HOME/bin"