java is not working in linux. Why?

て烟熏妆下的殇ゞ 提交于 2019-12-06 06:27:21

问题


Currently working on Linux Cinnamon. I have unistall/removed Open JDK from my local drive. Then I checked java -version via terminal and gives -

$ 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>

After that following the installation guide to install oracle jdk 8 for linux. Then I just checked java -version command through [I just unpack jdk to /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)

I set my environment variable JAVA_HOME="/opt/java/jdk1.8.0_112" [excluding bin] to /etc/environment using nano thereafter from JAVA_HOME setup tutorial -

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

and refresh & checked my JAVA_HOME as follows -

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

After these setup while I am trying check java -version via command it gives -

$ 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>

Can anyone tell me what is going on?


回答1:


Even once you set $JAVA_HOME, you still need to add bin to your $PATH:

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


来源:https://stackoverflow.com/questions/40322674/java-is-not-working-in-linux-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!