我在企业 linux 4 上安装了 jdk1.6.0_16,我还在 ~/.bash_profile 中设置了 JAVA_HOME
echo $JAVA_HOME 正确显示java文件的新路径
导出 JAVA_HOME=/jdk16/jdk1.6.0_16/bin/java
bin 目录也在路径中
但是,当我执行 java -version 时,我仍然看到 java 版本“1.4.2”
发出 java -version 命令时如何查看新安装的 jdk 版本
whereis java
Type that in, and it will show you the locations java is kept.
Or execute the java binary directly using: /jdk16/jdk1.6.0_16/bin/java -version
In addition to what PostMan said, you should also modify your PATH envvar in the following way:
export PATH=$JAVA_HOME:$PATH
put this in your bash_profile. This will guarantee you pick up the 1.60 jdk. Also your JAVA_HOME should probably be;
JAVA_HOME=/jdk16/jdk1.6.0_16/bin
that is you shouldn't put the path to the actual java executable in JAVA_HOME. It should point to the java installs bin directory.
Executing
which java
will tell you which jvm's executable you're running when you just run java -version.
With multiple JVMs installed, it's best to fully specify the path or set your PATH environment variable appropriately.
$ vi ~/.bash_profile
--> Add
export JAVA_HOME=<path to java jdk>
export PATH=$JAVA_HOME:$PATH
--> write/save
Esc + : + w
--> quit editor
Esc + : + q