java 版本仍然显示为 1.4 linux

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

java version still showing as 1.4 linux

javalinuxversionclasspath

提问by user229432

java -version still returns old java version. I have red hat linux

java -version 仍然返回旧的 java 版本。我有红帽 linux

I installed jdk 1.5 int eh follwing path and updated the bask profile and did a source but still the java version shows 1.4

我安装了 jdk 1.5 int eh follwing path 并更新了 bask 配置文件并做了一个源代码,但 Java 版本仍然显示 1.4

JAVA_HOME=/usr/local/jdk/jdk1.5.0_10/bin/java PATH has /usr/local/jdk/jdk1.5.0_10/bin

JAVA_HOME=/usr/local/jdk/jdk1.5.0_10/bin/java PATH 有 /usr/local/jdk/jdk1.5.0_10/bin

but i still see java -version even from the bin directory /usr/local/jdk/jdk1.5.0_10/bin as follows

但我仍然看到 java -version 即使从 bin 目录 /usr/local/jdk/jdk1.5.0_10/bin 如下

java -version

java - 版本

java version "1.4.2" gcj (GCC) 3.4.6 20060404 (Red Hat 3.4.6-10.0.1) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

java 版本 "1.4.2" gcj (GCC) 3.4.6 20060404 (Red Hat 3.4.6-10.0.1) 版权所有 (C) 2006 Free Software Foundation, Inc. 这是免费软件;请参阅复制条件的来源。没有保修;甚至不是为了特定目的的适销性或适合性。

回答by

You need to use the alternatives system to update the symlinks to the correct version of Java - see http://kbase.redhat.com/faq/docs/DOC-5593.

您需要使用替代系统将符号链接更新为正确的 Java 版本 - 请参阅http://kbase.redhat.com/faq/docs/DOC-5593

Install with:

安装:

/usr/sbin/alternatives --install /usr/bin/java java /opt/jre1.6???/bin/java 2

Configure with:

配置:

/usr/sbin/alternatives --config java

回答by Yoni Roit

but i still see java -version even from the bin directory /usr/local/jdk/jdk1.5.0_10/bin as follows

但我仍然看到 java -version 即使从 bin 目录 /usr/local/jdk/jdk1.5.0_10/bin 如下

Magic: run ./java -version

魔术:运行 ./java -version

Note the dot and slash - this tells to execute from current dir. Unlike DOS, on linux current dir is not in the executable search path by default

注意点和斜线 - 这告诉从当前目录执行。与 DOS 不同,在 linux 上,当前目录默认不在可执行搜索路径中

And yes, fix your $PATH

是的,修复你的 $PATH

回答by Steve g

Generally each distro has their own mechanism for choosing the version of Java to use. Also this mechanism generally allows Java to be setup differently for each user.

通常,每个发行版都有自己的机制来选择要使用的 Java 版本。此外,这种机制通常允许为每个用户设置不同的 Java。

Ubuntu- sudo update-alternatives --config java

Ubuntu- sudo update-alternatives --config java

Debian

Debian

Gentoo- Uses java-config

Gentoo- 使用 java-config

Fedora Coreuses alternatives --config java

Fedora Core使用替代方案 --config java

回答by Rob

Oh, yes.

哦是的。

sudo update-alternatives --config java

须藤更新替代品--config java

Displays:

显示:

There are 2 choices for the alternative java (providing /usr/bin/java).

替代 java 有 2 个选择(提供 /usr/bin/java)。

  Selection    Path                                      Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-openjdk/jre/bin/java   1051      manual mode

Then you can choose your version. In my case, Java-7 (option 2)

然后你可以选择你的版本。就我而言,Java-7(选项 2)

回答by TMN

Try issuing the command "which java" to discover exactly what version of the java command is being executed. If you just appended the new path to the end of your PATH, then the shell will still use the old one because it'll find that one first.

尝试发出命令“which java”以准确发现正在执行的 java 命令的版本。如果您只是将新路径附加到 PATH 的末尾,那么 shell 仍将使用旧路径,因为它会先找到那个路径。