java version still showing as 1.4 linux

我怕爱的太早我们不能终老 提交于 2019-12-11 02:09:32

问题


java -version still returns old java version. I have red hat 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

JAVA_HOME=/usr/local/jdk/jdk1.5.0_10/bin/java PATH has /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

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.


回答1:


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.

Install with:

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

Configure with:

/usr/sbin/alternatives --config java



回答2:


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

Magic: run ./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

And yes, fix your $PATH




回答3:


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.

Ubuntu - sudo update-alternatives --config java

Debian

Gentoo - Uses java-config

Fedora Core uses alternatives --config java




回答4:


Oh, yes.

sudo update-alternatives --config java

Displays:

There are 2 choices for the alternative java (providing /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)




回答5:


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.



来源:https://stackoverflow.com/questions/2165061/java-version-still-showing-as-1-4-linux

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