参考:https://www.cnblogs.com/Jakson/articles/4615768.html
摘要 :因为ubuntu 会自带open-jdk预装在系统内,当我们需要在 ubuntu下 安装jdk 的时候 ,发现 即使配置好环境变量后 输入 java -version 版本还是依然没有发生变化,我们需要以下2个步骤切换/usr/local/java 指向的 jdk
我们需要把新版本的java 命令更新到系统的 /usr/bin/ 下 301为优先级
##############################################
root@ubuntu:/home/linyujie/software/jdk# update-alternatives --install /usr/bin/java java /home/linyujie/software/jdk/jdk1.8/bin/java 301
root@ubuntu:/home/linyujie/software/jdk# update-alternatives --install /usr/bin/javac javac /home/linyujie/software/jdk/jdk1.8/bin/javac 301
##############################################
这时候再次输入 update-alternatives --config java,就会提示有多个版本的jdk,输入数字选择需要的jdk。这里输入1
##############################################
root@ubuntu:/home/linyujie/software/jdk# update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
- 0 /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java 1061 auto mode
1 /home/linyujie/software/jdk/jdk1.8/bin/java 301 manual mode
2 /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java 1061 manual mode
Press enter to keep the current choice[*], or type selection number: 1
##############################################
最后验证一下输入命令 java -version
##############################################
root@ubuntu:/home/linyujie/software/jdk# java -version
java version “1.8.0_45”
Java™ SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot™ Server VM (build 25.45-b02, mixed mode)
##############################################