且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JAVA_HOME 和 PATH 已设置,但 java -version 仍显示旧版本

更新时间:2023-01-14 22:53:58

虽然您的设置看起来是正确的,但有几件事需要检查:

While it looks like your setup is correct, there are a few things to check:

  1. env 的输出 - 特别是 PATH.
  2. command -v java 告诉你什么?
  3. $JAVA_HOMEin 中是否有一个java 可执行文件,它是否设置了执行位?如果不是 chmod a+x java 它.
  1. The output of env - specifically PATH.
  2. command -v java tells you what?
  3. Is there a java executable in $JAVA_HOMEin and does it have the execute bit set? If not chmod a+x java it.

我相信在添加/更改 JAVA_HOMEPATH 之后,您的 .profile 已经 source 了?

I trust you have source'd your .profile after adding/changing the JAVA_HOME and PATH?

另外,您可以通过编写以下代码来帮助自己在将来维护 JDK 安装:

Also, you can help yourself in future maintenance of your JDK installation by writing this instead:

export JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=$JAVA_HOME/bin:$PATH

那么你在安装JDK的时候只需要更新一个环境变量.

Then you only need to update one env variable when you setup the JDK installation.

最后,您可能需要运行 hash -r 来清除 Bash 程序缓存.其他 shell 可能需要类似的命令.

Finally, you may need to run hash -r to clear the Bash program cache. Other shells may need a similar command.

干杯,