linux下jdk多版本切换
系统环境
-
系统 almalinux 9
-
java Orcale jdk1.8 & jdk17
-
jdk 安装方式 yum localinstall rpm包 (注:安装jdk时未对
/etc/profile
进行更改)
如何切换
使用alternatives --config java
更改jdk版本
[root@minato ~]# alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
1 /usr/java/jdk1.8.0_351-amd64/bin/java
*+ 2 /usr/java/jdk-17.0.5/bin/java
Enter to keep the current selection[+], or type selection number: 1
[root@minato ~]# java -version
java version "1.8.0_351"
Java(TM) SE Runtime Environment (build 1.8.0_351-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.351-b10, mixed mode)
---
发现alternatives
完全是巧合,是探究rpm安装未配置profile命令如何生效发现的。
先使用whereis
查看java位置,发现它是在/usr/bin
目录下。
[root@minato ~]# whereis java
java: /usr/bin/java /usr/share/man/man1/java.1
然后卸载,不论那个版本,都是在这个位置,然后查看/usr/bin
目录
[root@minato ~]# cd /usr/bin/
[root@minato bin]# ll|grep java
lrwxrwxrwx 1 root root 22 Dec 5 08:18 java -> /etc/alternatives/java
lrwxrwxrwx 1 root root 23 Dec 5 08:18 javac -> /etc/alternatives/javac
lrwxrwxrwx 1 root root 25 Dec 5 08:18 javadoc -> /etc/alternatives/javadoc
lrwxrwxrwx 1 root root 32 Dec 5 08:18 javafxpackager -> /etc/alternatives/javafxpackager
lrwxrwxrwx 1 root root 23 Dec 5 08:18 javah -> /etc/alternatives/javah
lrwxrwxrwx 1 root root 23 Dec 5 08:18 javap -> /etc/alternatives/javap
lrwxrwxrwx 1 root root 30 Dec 5 08:18 javapackager -> /etc/alternatives/javapackager
lrwxrwxrwx 1 root root 30 Dec 5 08:18 java-rmi.cgi -> /etc/alternatives/java-rmi.cgi
lrwxrwxrwx 1 root root 24 Dec 5 08:18 javaws -> /etc/alternatives/javaws
发现,这里面的java是个链接,继续查下去
[root@minato bin]# cd /etc/alternatives/
[root@minato alternatives]# ll|grep java
lrwxrwxrwx 1 root root 45 Dec 5 08:18 appletviewer -> /usr/java/jdk1.8.0_351-amd64/bin/appletviewer
lrwxrwxrwx 1 root root 52 Dec 5 08:18 appletviewer.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/appletviewer.1
lrwxrwxrwx 1 root root 45 Dec 5 08:18 ControlPanel -> /usr/java/jdk1.8.0_351-amd64/bin/ControlPanel
lrwxrwxrwx 1 root root 41 Dec 5 08:18 extcheck -> /usr/java/jdk1.8.0_351-amd64/bin/extcheck
lrwxrwxrwx 1 root root 48 Dec 5 08:18 extcheck.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/extcheck.1
lrwxrwxrwx 1 root root 37 Dec 5 08:18 idlj -> /usr/java/jdk1.8.0_351-amd64/bin/idlj
lrwxrwxrwx 1 root root 44 Dec 5 08:18 idlj.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/idlj.1
lrwxrwxrwx 1 root root 36 Dec 5 08:18 jar -> /usr/java/jdk1.8.0_351-amd64/bin/jar
lrwxrwxrwx 1 root root 43 Dec 5 08:18 jar.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jar.1
lrwxrwxrwx 1 root root 42 Dec 5 08:18 jarsigner -> /usr/java/jdk1.8.0_351-amd64/bin/jarsigner
lrwxrwxrwx 1 root root 49 Dec 5 08:18 jarsigner.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jarsigner.1
lrwxrwxrwx 1 root root 37 Dec 5 08:18 java -> /usr/java/jdk1.8.0_351-amd64/bin/java
lrwxrwxrwx 1 root root 44 Dec 5 08:18 java.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/java.1
lrwxrwxrwx 1 root root 38 Dec 5 08:18 javac -> /usr/java/jdk1.8.0_351-amd64/bin/javac
lrwxrwxrwx 1 root root 45 Dec 5 08:18 javac.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/javac.1
lrwxrwxrwx 1 root root 40 Dec 5 08:18 javadoc -> /usr/java/jdk1.8.0_351-amd64/bin/javadoc
lrwxrwxrwx 1 root root 47 Dec 5 08:18 javadoc.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/javadoc.1
lrwxrwxrwx 1 root root 47 Dec 5 08:18 javafxpackager -> /usr/java/jdk1.8.0_351-amd64/bin/javafxpackager
lrwxrwxrwx 1 root root 54 Dec 5 08:18 javafxpackager.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/javafxpackager.1
lrwxrwxrwx 1 root root 38 Dec 5 08:18 javah -> /usr/java/jdk1.8.0_351-amd64/bin/javah
lrwxrwxrwx 1 root root 45 Dec 5 08:18 javah.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/javah.1
lrwxrwxrwx 1 root root 38 Dec 5 08:18 javap -> /usr/java/jdk1.8.0_351-amd64/bin/javap
lrwxrwxrwx 1 root root 45 Dec 5 08:18 javap.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/javap.1
lrwxrwxrwx 1 root root 45 Dec 5 08:18 javapackager -> /usr/java/jdk1.8.0_351-amd64/bin/javapackager
lrwxrwxrwx 1 root root 52 Dec 5 08:18 javapackager.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/javapackager.1
lrwxrwxrwx 1 root root 45 Dec 5 08:18 java-rmi.cgi -> /usr/java/jdk1.8.0_351-amd64/bin/java-rmi.cgi
lrwxrwxrwx 1 root root 39 Dec 5 08:18 javaws -> /usr/java/jdk1.8.0_351-amd64/bin/javaws
lrwxrwxrwx 1 root root 46 Dec 5 08:18 javaws.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/javaws.1
lrwxrwxrwx 1 root root 37 Dec 5 08:18 jcmd -> /usr/java/jdk1.8.0_351-amd64/bin/jcmd
lrwxrwxrwx 1 root root 44 Dec 5 08:18 jcmd.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jcmd.1
lrwxrwxrwx 1 root root 41 Dec 5 08:18 jconsole -> /usr/java/jdk1.8.0_351-amd64/bin/jconsole
lrwxrwxrwx 1 root root 48 Dec 5 08:18 jconsole.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jconsole.1
lrwxrwxrwx 1 root root 41 Dec 5 08:18 jcontrol -> /usr/java/jdk1.8.0_351-amd64/bin/jcontrol
lrwxrwxrwx 1 root root 36 Dec 5 08:18 jdb -> /usr/java/jdk1.8.0_351-amd64/bin/jdb
lrwxrwxrwx 1 root root 43 Dec 5 08:18 jdb.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jdb.1
lrwxrwxrwx 1 root root 38 Dec 5 08:18 jdeps -> /usr/java/jdk1.8.0_351-amd64/bin/jdeps
lrwxrwxrwx 1 root root 45 Dec 5 08:18 jdeps.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jdeps.1
lrwxrwxrwx 1 root root 37 Dec 5 08:18 jhat -> /usr/java/jdk1.8.0_351-amd64/bin/jhat
lrwxrwxrwx 1 root root 44 Dec 5 08:18 jhat.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jhat.1
lrwxrwxrwx 1 root root 38 Dec 5 08:18 jinfo -> /usr/java/jdk1.8.0_351-amd64/bin/jinfo
lrwxrwxrwx 1 root root 45 Dec 5 08:18 jinfo.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jinfo.1
lrwxrwxrwx 1 root root 36 Dec 5 08:18 jjs -> /usr/java/jdk1.8.0_351-amd64/bin/jjs
lrwxrwxrwx 1 root root 43 Dec 5 08:18 jjs.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jjs.1
lrwxrwxrwx 1 root root 37 Dec 5 08:18 jmap -> /usr/java/jdk1.8.0_351-amd64/bin/jmap
lrwxrwxrwx 1 root root 44 Dec 5 08:18 jmap.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jmap.1
lrwxrwxrwx 1 root root 36 Dec 5 08:18 jps -> /usr/java/jdk1.8.0_351-amd64/bin/jps
lrwxrwxrwx 1 root root 43 Dec 5 08:18 jps.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jps.1
lrwxrwxrwx 1 root root 43 Dec 5 08:18 jrunscript -> /usr/java/jdk1.8.0_351-amd64/bin/jrunscript
lrwxrwxrwx 1 root root 50 Dec 5 08:18 jrunscript.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jrunscript.1
lrwxrwxrwx 1 root root 42 Dec 5 08:18 jsadebugd -> /usr/java/jdk1.8.0_351-amd64/bin/jsadebugd
lrwxrwxrwx 1 root root 49 Dec 5 08:18 jsadebugd.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jsadebugd.1
lrwxrwxrwx 1 root root 39 Dec 5 08:18 jstack -> /usr/java/jdk1.8.0_351-amd64/bin/jstack
lrwxrwxrwx 1 root root 46 Dec 5 08:18 jstack.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jstack.1
lrwxrwxrwx 1 root root 38 Dec 5 08:18 jstat -> /usr/java/jdk1.8.0_351-amd64/bin/jstat
lrwxrwxrwx 1 root root 45 Dec 5 08:18 jstat.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jstat.1
lrwxrwxrwx 1 root root 39 Dec 5 08:18 jstatd -> /usr/java/jdk1.8.0_351-amd64/bin/jstatd
lrwxrwxrwx 1 root root 46 Dec 5 08:18 jstatd.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jstatd.1
lrwxrwxrwx 1 root root 42 Dec 5 08:18 jvisualvm -> /usr/java/jdk1.8.0_351-amd64/bin/jvisualvm
lrwxrwxrwx 1 root root 49 Dec 5 08:18 jvisualvm.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/jvisualvm.1
lrwxrwxrwx 1 root root 40 Dec 5 08:18 keytool -> /usr/java/jdk1.8.0_351-amd64/bin/keytool
lrwxrwxrwx 1 root root 47 Dec 5 08:18 keytool.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/keytool.1
lrwxrwxrwx 1 root root 45 Dec 5 08:18 native2ascii -> /usr/java/jdk1.8.0_351-amd64/bin/native2ascii
lrwxrwxrwx 1 root root 52 Dec 5 08:18 native2ascii.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/native2ascii.1
lrwxrwxrwx 1 root root 37 Dec 5 08:18 orbd -> /usr/java/jdk1.8.0_351-amd64/bin/orbd
lrwxrwxrwx 1 root root 44 Dec 5 08:18 orbd.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/orbd.1
lrwxrwxrwx 1 root root 40 Dec 5 08:18 pack200 -> /usr/java/jdk1.8.0_351-amd64/bin/pack200
lrwxrwxrwx 1 root root 47 Dec 5 08:18 pack200.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/pack200.1
lrwxrwxrwx 1 root root 43 Dec 5 08:18 policytool -> /usr/java/jdk1.8.0_351-amd64/bin/policytool
lrwxrwxrwx 1 root root 50 Dec 5 08:18 policytool.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/policytool.1
lrwxrwxrwx 1 root root 37 Dec 5 08:18 rmic -> /usr/java/jdk1.8.0_351-amd64/bin/rmic
lrwxrwxrwx 1 root root 44 Dec 5 08:18 rmic.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/rmic.1
lrwxrwxrwx 1 root root 37 Dec 5 08:18 rmid -> /usr/java/jdk1.8.0_351-amd64/bin/rmid
lrwxrwxrwx 1 root root 44 Dec 5 08:18 rmid.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/rmid.1
lrwxrwxrwx 1 root root 44 Dec 5 08:18 rmiregistry -> /usr/java/jdk1.8.0_351-amd64/bin/rmiregistry
lrwxrwxrwx 1 root root 51 Dec 5 08:18 rmiregistry.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/rmiregistry.1
lrwxrwxrwx 1 root root 42 Dec 5 08:18 schemagen -> /usr/java/jdk1.8.0_351-amd64/bin/schemagen
lrwxrwxrwx 1 root root 49 Dec 5 08:18 schemagen.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/schemagen.1
lrwxrwxrwx 1 root root 42 Dec 5 08:18 serialver -> /usr/java/jdk1.8.0_351-amd64/bin/serialver
lrwxrwxrwx 1 root root 49 Dec 5 08:18 serialver.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/serialver.1
lrwxrwxrwx 1 root root 43 Dec 5 08:18 servertool -> /usr/java/jdk1.8.0_351-amd64/bin/servertool
lrwxrwxrwx 1 root root 50 Dec 5 08:18 servertool.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/servertool.1
lrwxrwxrwx 1 root root 42 Dec 5 08:18 tnameserv -> /usr/java/jdk1.8.0_351-amd64/bin/tnameserv
lrwxrwxrwx 1 root root 49 Dec 5 08:18 tnameserv.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/tnameserv.1
lrwxrwxrwx 1 root root 42 Dec 5 08:18 unpack200 -> /usr/java/jdk1.8.0_351-amd64/bin/unpack200
lrwxrwxrwx 1 root root 49 Dec 5 08:18 unpack200.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/unpack200.1
lrwxrwxrwx 1 root root 38 Dec 5 08:18 wsgen -> /usr/java/jdk1.8.0_351-amd64/bin/wsgen
lrwxrwxrwx 1 root root 45 Dec 5 08:18 wsgen.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/wsgen.1
lrwxrwxrwx 1 root root 41 Dec 5 08:18 wsimport -> /usr/java/jdk1.8.0_351-amd64/bin/wsimport
lrwxrwxrwx 1 root root 48 Dec 5 08:18 wsimport.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/wsimport.1
lrwxrwxrwx 1 root root 36 Dec 5 08:18 xjc -> /usr/java/jdk1.8.0_351-amd64/bin/xjc
lrwxrwxrwx 1 root root 43 Dec 5 08:18 xjc.1 -> /usr/java/jdk1.8.0_351-amd64/man/man1/xjc.1
这个对应的就是jdk的安装地址了。
查找/etc/alternatives
目录是做什么的,发现alternatives
这个命令。
本文来自博客园,作者:康舒服冰红茶,转载请注明原文链接:https://www.cnblogs.com/pong137/p/16954596.html
欢迎转载,但请注明「作者」和「原文地址」。转载请在文中保留此段,感谢您对作者版权的尊重。如需商业转载或刊登,请联系作者获得授权。