[root@danny lib]# cd /usr/lib/jvm [root@danny jvm]# [root@danny jvm]# ls java java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64 jre-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64 java-1.7.0 java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64-debug jre-1.8.0 java-1.7.0-openjdk java-openjdk jre-1.8.0-openjdk java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64 jre jre-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64 java-1.8.0 jre-1.7.0 jre-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64-debug java-1.8.0-openjdk jre-1.7.0-openjdk jre-openjdk [root@danny jvm]# ll total 12 lrwxrwxrwx 1 root root 26 Nov 5 13:27 java -> /etc/alternatives/java_sdk lrwxrwxrwx 1 root root 32 Nov 5 13:27 java-1.7.0 -> /etc/alternatives/java_sdk_1.7.0 lrwxrwxrwx 1 root root 40 Nov 5 13:27 java-1.7.0-openjdk -> /etc/alternatives/java_sdk_1.7.0_openjdk drwxr-xr-x 10 root root 4096 Nov 5 13:27 java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64 lrwxrwxrwx 1 root root 32 Sep 5 16:54 java-1.8.0 -> /etc/alternatives/java_sdk_1.8.0 lrwxrwxrwx 1 root root 40 Sep 5 16:54 java-1.8.0-openjdk -> /etc/alternatives/java_sdk_1.8.0_openjdk drwxr-xr-x 9 root root 4096 Nov 5 13:40 java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64 drwxr-xr-x 9 root root 4096 Sep 5 16:54 java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64-debug lrwxrwxrwx 1 root root 34 Nov 5 13:27 java-openjdk -> /etc/alternatives/java_sdk_openjdk lrwxrwxrwx 1 root root 21 Nov 5 13:27 jre -> /etc/alternatives/jre lrwxrwxrwx 1 root root 27 Nov 5 13:27 jre-1.7.0 -> /etc/alternatives/jre_1.7.0 lrwxrwxrwx 1 root root 35 Nov 5 13:27 jre-1.7.0-openjdk -> /etc/alternatives/jre_1.7.0_openjdk lrwxrwxrwx 1 root root 54 Nov 5 13:27 jre-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64 -> java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64/jre lrwxrwxrwx 1 root root 27 Sep 5 16:54 jre-1.8.0 -> /etc/alternatives/jre_1.8.0 lrwxrwxrwx 1 root root 35 Sep 5 16:54 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk lrwxrwxrwx 1 root root 51 Sep 5 16:54 jre-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64 -> java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre lrwxrwxrwx 1 root root 57 Sep 5 16:54 jre-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64-debug -> java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64-debug/jre lrwxrwxrwx 1 root root 29 Nov 5 13:27 jre-openjdk -> /etc/alternatives/jre_openjdk [root@danny jvm]# ls /etc/alternatives/java_sdk bin demo include jre lib sample src.zip tapset
[root@danny jvm]# alternatives --config java (版本切换) There are 3 programs which provide 'java'. Selection Command ----------------------------------------------- 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64-debug/jre/bin/java) *+ 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre/bin/java) (当前版本) 3 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64/jre/bin/java) Enter to keep the current selection[+], or type selection number: 3 (切换为1.7版本) [root@danny jvm]# alternatives --config java (以下可以看到+号在1.7版本处,不变还是输入3退出) There are 3 programs which provide 'java'. Selection Command ----------------------------------------------- 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64-debug/jre/bin/java) * 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre/bin/java) + 3 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64/jre/bin/java) Enter to keep the current selection[+], or type selection number: 3 [root@danny jvm]# java -version (可以看到已经变为1.7版本了) java version "1.7.0_191" OpenJDK Runtime Environment (rhel-2.6.15.4.el7_5-x86_64 u191-b01) OpenJDK 64-Bit Server VM (build 24.191-b01, mixed mode)
注释:在探究linux中jdk版本切换时发现了如下一行
lrwxrwxrwx 1 root root 26 Nov 5 13:27 java -> /etc/alternatives/java_sdk
网上搜了以下alternatives这个文件是什么东东时,才发现这是一个可以进行jdk版本切换的命令,命令格式如下:
alternatives --config java