First install java
http://www.cnblogs.com/someone9/p/8670585.html
2. Then check the version information, it is still 1.5.0
[root@OKC java]# java -version java version "1.5.0" thou (GNU libgcj) version 4.4.7 20120313 (Red Hat 4.4.7-18) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
3. Then execute
[root@OKC ~]# alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_161/bin/ 300 appletviewer javac javaws jinfo jsadebugd orbd serialver ControlPanel javadoc jcmd jjs jstack pack200 servertool extcheck javafxpackager jconsole jmap jstat policytool tnameserv idlj javah jcontrol jmc jstatd rmic unpack200 jar javap jdb jmc.ini jvisualvm rmid wsgen jarsigner javapackager jdeps jps keytool rmiregistry wsimport java java-rmi.cgi jhat jrunscript native2ascii schemagen xjc
4. Select the configuration and fill in 3. The environment we just configured
[root@OKC ~]# alternatives --config java There are 3 programs which provide 'java'. Selection Command ----------------------------------------------- * 1 /usr/lib/jvm/jre-1.5.0-gcj/bin/java + 2 /usr/bin/java/jdk1.8.0_161/bin/java 3 /usr/java/jdk1.8.0_161/bin/java Enter to keep the current selection[+], or type selection number: 3
5. Check the version information again
[root@OKC ~]# java -version java version "1.8.0_161" Java(TM) SE Runtime Environment (build 1.8.0_161-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
Note:
If the configuration in the third step is not the location we installed, or if it exceeds the scope of the directory, an error will be reported
-bash: /usr/bin/java: Too many levels of symbolic links
can be reconfigured according to the third step above
[root@OKC java]# alternatives --install /usr/bin/java java /usr/bin/java/jdk1.8.0_161/bin/java 300 [root@OKC java]# java -version java version "1.5.0" thou (GNU libgcj) version 4.4.7 20120313 (Red Hat 4.4.7-18) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. [root@OKC java]# alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- *+ 1 /usr/lib/jvm/jre-1.5.0-gcj/bin/java 2 /usr/bin/java/jdk1.8.0_161/bin/java Enter to keep the current selection[+], or type selection number: 2 [root@OKC java]# java -version -bash: /usr/bin/java: Too many levels of symbolic links