java --version shows 10 but java 11 is installed

问题: Previously I had java 8 installed by default. After upgrading java version to 11 it shows openjdk 10.0.2 2018-07-17. I downloaded jdk-11.0.2_linux-x64_bin.deb from oracle...

问题:

Previously I had java 8 installed by default. After upgrading java version to 11 it shows openjdk 10.0.2 2018-07-17.

I downloaded jdk-11.0.2_linux-x64_bin.deb from oracle site and installed it. After that I ran sudo update-alternatives --config java to change the version to 11 but after running java --version command I get following output:

openjdk 10.0.2 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.4, mixed mode)

output of javac --version:

javac 10.0.2

回答1:

You are getting confused between openjdk and oracle jdk. You have installed openjdk 11 and hence it shows you version as 10. You can update the alternatives and reconfigure it:

Remove openjdk 11:

sudo update-alternatives --remove "java" "/usr/lib/jvm/java-11-openjdk-amd64/bin/java"
sudo update-alternatives --remove "java" "/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java"

sudo update-alternatives --remove "javac" "/usr/lib/jvm/java-11-openjdk-amd64/bin/javac"
sudo update-alternatives --remove "javac" "/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/javac"

If you wish, you can delete the openjdk folders using:

sudo rm -r /usr/lib/jvm/java-11-openjdk-amd64/
sudo rm -r /usr/lib/jvm/java-1.11.0-openjdk-amd64/

update alternatives install oracle jdk:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11.0.2/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-11.0.2/bin/javac 1

Reconfigure:

sudo update-alternatives --config java
sudo update-alternatives --config javac

Now run the java --version and you will get the output as java 11.0.2.

  • 发表于 2019-03-19 01:52
  • 阅读 ( 192 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除