如何在CentOS

时间:2016-06-13 17:55:41

标签: java-8 openjdk

我想在CentOS机器上更新java版本,

实际上,当我做java -version时,它给了我:

$java -version
java version "1.7.0_79"
OpenJDK Runtime Environment (rhel-2.5.5.3.el6_6-x86_64 u79-b14)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)

我正在使用替代方案来配置应该使用哪个java解释器:

 sudo alternatives --config java
它给了我:

There are 3 programs which provide 'java'.

      Selection    Command
    -----------------------------------------------
    *  1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
       2           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
     + 3           /usr/lib/jvm/jdk1.8.0_91/bin/java

Enter to keep the current selection[+], or type selection number:

我选择了3号(这是jdk1.8.0_91)

然而,当我重做java -version时,它仍然选择了openJDK 1.7!

$java -version
java version "1.7.0_79"
OpenJDK Runtime Environment (rhel-2.5.5.3.el6_6-x86_64 u79-b14)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)

1 个答案:

答案 0 :(得分:1)

运行以下命令检查配置:

  • $ which java,结果应为/bin/java/usr/bin/java。否则,请检查您的环境配置文件(/ etc / bashrc,/ etc / profile,〜/ .bash_profile,〜/ .bashrc等)并删除声明的类似export JAVA_HOME="/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/jre"
  • $ ls -al /bin/java$ ls -al /usr/bin/java应指向/etc/alternatives/java或替代方案无效。