java:找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26893041/
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-02 10:49:16  来源:igfitidea点击:

java : command not find

javacentos

提问by arVahedi


i have a problem with install jdk on my centos.
i did install "java-1.8.0-openjdk-1.8.0.25-3.b17.el6_6.i386" but yet when i run "java -version", i see this error:


我在 Centos 上安装 jdk 时遇到问题。
我确实安装了“java-1.8.0-openjdk-1.8.0.25-3.b17.el6_6.i386”但是当我运行“java -version”时,我看到了这个错误:

[root@JAVA java]# java -version

-bash: java: command not found

i set $PATH variable too:

我也设置了 $PATH 变量:

[root@JAVA java]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/root/bin:/root/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.25-3.b17.el6_6.i386/jre/bin:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.25-3.b17.el6_6.i386/jre/bin/

what is wrong? i really tried to search. :( plz help me.

怎么了?我真的试图搜索。:(请帮帮我。

update:
i locate for jre and this return:

更新
我找到了 jre 并且这次返回:

[root@JAVA java]# locate jre
/etc/alternatives/jre
/etc/alternatives/jre_1.8.0
/etc/alternatives/jre_1.8.0_exports
/etc/alternatives/jre_1.8.0_openjdk
/etc/alternatives/jre_1.8.0_openjdk_exports
/etc/alternatives/jre_exports
/etc/alternatives/jre_openjdk
/etc/alternatives/jre_openjdk_exports
/usr/lib/jvm/jre
/usr/lib/jvm/jre-1.7.0
/usr/lib/jvm/jre-1.7.0-openjdk
/usr/lib/jvm/jre-1.8.0
/usr/lib/jvm/jre-1.8.0-openjdk
/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.25-3.b17.el6_6.i386
/usr/lib/jvm/jre-openjdk
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.25-3.b17.el6_6.i386/jre
/usr/lib/jvm-exports/jre
/usr/lib/jvm-exports/jre-1.7.0
/usr/lib/jvm-exports/jre-1.7.0-openjdk
/usr/lib/jvm-exports/jre-1.8.0
/usr/lib/jvm-exports/jre-1.8.0-openjdk-1.8.0.25-3.b17.el6_6.i386
/usr/lib/jvm-exports/jre-openjdk
/var/lib/alternatives/jre_1.7.0
/var/lib/alternatives/jre_1.8.0
/var/lib/alternatives/jre_1.8.0_openjdk
/var/lib/alternatives/jre_openjdk

which that is current path?

这是当前路径?

update 2:

更新2:

[root@JAVA java]# yum list installed| grep java
java-1.7.0-openjdk.i686  1:1.7.0.65-2.5.1.2.el6_5
java-1.7.0-openjdk-devel.i686
java-1.8.0-openjdk.i686  1.8.0.25-3.b17.el6_6
java-1.8.0-openjdk-devel.i686
java-1.8.0-openjdk-headless.i686
tzdata-java.noarch       2014h-1.el6     @updates
[root@JAVA java]# find / -name "java"
/usr/share/bash-completion/java
/usr/share/java
/usr/lib/java
/usr/lib/jvm-exports/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.25-3.b17.el6_6.i386/bin/java
/usr/lib/jvm/java
/usr/bin/java
/var/lib/alternatives/java
/etc/alternatives/java
/etc/pki/java
/etc/java

回答by Altmish-E-Azam

Add below two lines in bashrcand profilefiles in /etc directory.

在 /etc 目录中的bashrcandprofile文件中添加以下两行。

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.25-3.b17.el6_6.i386
export PATH=$JAVA_HOME/bin:$PATH

And try java -version. Still any problem please restart your OS once.

并尝试java -version。仍然有任何问题,请重新启动您的操作系统一次。

回答by sergpank

if you are going to compile some java code you gonna need to use javaccommand which is located at JDK/bin/. All your system is targeted on JDK/jre/bin.

如果要编译一些 Java 代码,则需要使用javac位于JDK/bin/. 您的所有系统都针对JDK/jre/bin.

If there is no java configured create a symlink at /usr/bin

如果没有配置java,请在以下位置创建符号链接 /usr/bin

cd /usr/bin
ln -sfvn /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.25-3.b17.el6_6.i386/bin/java java

The better and cleaner approach is to create symlink javawhich will let you easily update java version in future:

更好更简洁的方法是创建符号链接java,让您在未来轻松更新 Java 版本:

cd /usr/lib/jvm/
ln -sfvn java-1.8.0-openjdk-1.8.0.25-3.b17.el6_6.i386 java
ln -sfvn java/jre jre

cd /usr/bin
ln -sfvn /usr/lb/jvm/java/bin/java java

Such approach will give you a cleaner and clearer environment.

这种方法会给你一个更干净、更清晰的环境。

You can also try alternativescommand - Why is alternatives command used when installing Java on a Linux machine

您也可以尝试alternatives命令 -为什么在 Linux 机器上安装 Java 时使用替代命令

But this is not really necessary.

但这并不是真正必要的。