要搞整最新2.1版本的elasticsearch,最好用jdk 1.8。CentOS7默认的却是1.7,所以得升个级。
首先看图一目了解java的架构
JDK 8 is a superset of JRE 8, and contains everything that is inJRE 8, plus tools such as the compilers and debuggers necessary fordeveloping applets and applications. JRE 8 provides the libraries,the Java Virtual Machine (JVM), and other components to run appletsand applications written in the Java programming language. Notethat the JRE includes components not required by the Java SEspecification, including both standard and non-standard Javacomponents.
一、CenOS7默认的jdk 1.7
/usr/bin/java首先链接到/etc/alternatives/java,再链接到具体的openjdk
# java -version
java version "1.7.0_91"
OpenJDK Runtime Environment (rhel-2.6.2.1.el7_1-x86_64 u91-b00)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)
# which java
/usr/bin/java
# ll /usr/bin/java
lrwxrwxrwx. 1 root root 22 Dec 2 00:46 /usr/bin/java -> /etc/alternatives/java
# ll /etc/alternatives/java
lrwxrwxrwx. 1 root root 74 Dec 2 00:46 /etc/alternatives/java -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/java
]# rpm -qa | grep java
java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
javapackages-tools-3.4.1-6.el7_0.noarch
python-javapackages-3.4.1-6.el7_0.noarch
tzdata-java-2015g-1.el7.noarch
java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.1.el7_1.x86_64
# rpm -qa | grep jdk
java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.1.el7_1.x86_64
# ll /usr/share/
......
drwxr-xr-x. 2 root root 94 Sep 20 21:37 java
drwxr-xr-x. 2 root root 6 Aug 14 2014 java-1.5.0
drwxr-xr-x. 2 root root 6 Aug 14 2014 java-1.6.0
drwxr-xr-x. 2 root root 6 Aug 14 2014 java-1.7.0
drwxr-xr-x. 2 root root 6 Aug 14 2014 java-1.8.0
drwxr-xr-x. 2 root root 6 Aug 14 2014 javadoc
drwxr-xr-x. 2 root root 6 Aug 14 2014 java-ext
drwxr-xr-x. 2 root root 4096 Sep 20 21:33 java-utils
drwxr-xr-x. 13 root root 4096 Oct 10 05:56 javazi
drwxr-xr-x. 2 root root 21 Oct 10 05:56 javazi-1.8
drwxr-xr-x. 2 root root 6 Aug 14 2014 jvm
drwxr-xr-x. 2 root root 6 Aug 14 2014 jvm-commmon
......
上面的几个版本从1.5到1.8的文件夹都是空的。
# ll /usr/lib/
......
drwxr-xr-x. 2 root root 6 Aug 14 2014 java
drwxr-xr-x. 2 root root 6 Aug 14 2014 java-1.5.0
drwxr-xr-x. 2 root root 6 Aug 14 2014 java-1.6.0
drwxr-xr-x. 2 root root 6 Aug 14 2014 java-1.7.0
drwxr-xr-x. 2 root root 6 Aug 14 2014 java-1.8.0
drwxr-xr-x. 2 root root 6 Aug 14 2014 java-ext
drwxr-xr-x. 3 root root 4096 Dec 2 00:46 jvm
drwxr-xr-x. 2 root root 6 Aug 14 2014 jvm-commmon
drwxr-xr-x. 3 root root 4096 Dec 2 00:46 jvm-exports
drwxr-xr-x. 3 root root 61 Nov 21 18:47 jvm-private
......
而这几个文件夹从java到java-1.8.0到java-ext都是空的;jre文件全都在
/usr/lib/jvm文件夹中
# ll /usr/lib/jvm
total 8
drwxr-xr-x. 3 root root 4096 Dec 2 00:46 .
dr-xr-xr-x. 42 root root 4096 Nov 25 17:22 ..
drwxr-xr-x. 4 root root 95 Nov 21 18:46 java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
lrwxrwxrwx. 1 root root 21 Dec 2 00:46 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 27 Nov 21 18:47 jre-1.7.0 -> /etc/alternatives/jre_1.7.0
lrwxrwxrwx. 1 root root 35 Nov 21 18:47 jre-1.7.0-openjdk -> /etc/alternatives/jre_1.7.0_openjdk
lrwxrwxrwx. 1 root root 52 Nov 21 18:46 jre-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64 -> java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre
lrwxrwxrwx. 1 root root 29 Nov 21 18:47 jre-openjdk -> /etc/alternatives/jre_openjdk
这里看到很多东西链接到了/etc/alternatives,这个alternatives感觉像是个跳板或者统一接口API之类的一样的性质
$ ll /etc/alternatives/ | grep -E "java|jre"
lrwxrwxrwx. 1 root root 74 Nov 21 18:47 java -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/java
lrwxrwxrwx. 1 root root 78 Nov 21 18:47 java.1.gz -> /usr/share/man/man1/java-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 21 Sep 20 09:41 javaws -> /usr/bin/javaws.itweb
lrwxrwxrwx. 1 root root 37 Sep 20 09:41 javaws.1.gz -> /usr/share/man/man1/javaws-itweb.1.gz
lrwxrwxrwx. 1 root root 65 Nov 21 18:47 jre -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre
lrwxrwxrwx. 1 root root 65 Nov 21 18:47 jre_1.7.0 -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre
lrwxrwxrwx. 1 root root 69 Nov 21 18:47 jre_1.7.0_exports -> /usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
lrwxrwxrwx. 1 root root 60 Nov 21 18:47 jre_1.7.0_openjdk -> /usr/lib/jvm/jre-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
lrwxrwxrwx. 1 root root 69 Nov 21 18:47 jre_1.7.0_openjdk_exports -> /usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
lrwxrwxrwx. 1 root root 69 Nov 21 18:47 jre_exports -> /usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
lrwxrwxrwx. 1 root root 65 Nov 21 18:47 jre_openjdk -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre
lrwxrwxrwx. 1 root root 69 Nov 21 18:47 jre_openjdk_exports -> /usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
lrwxrwxrwx. 1 root root 77 Nov 21 18:47 keytool -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/keytool
lrwxrwxrwx. 1 root root 81 Nov 21 18:47 keytool.1.gz -> /usr/share/man/man1/keytool-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 27 Sep 20 09:41 libjavaplugin.so.x86_64 -> /usr/lib64/IcedTeaPlugin.so
lrwxrwxrwx. 1 root root 74 Nov 21 18:47 orbd -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/orbd
lrwxrwxrwx. 1 root root 78 Nov 21 18:47 orbd.1.gz -> /usr/share/man/man1/orbd-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 77 Nov 21 18:47 pack200 -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/pack200
lrwxrwxrwx. 1 root root 81 Nov 21 18:47 pack200.1.gz -> /usr/share/man/man1/pack200-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 74 Nov 21 18:47 rmid -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/rmid
lrwxrwxrwx. 1 root root 78 Nov 21 18:47 rmid.1.gz -> /usr/share/man/man1/rmid-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 81 Nov 21 18:47 rmiregistry -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/rmiregistry
lrwxrwxrwx. 1 root root 85 Nov 21 18:47 rmiregistry.1.gz -> /usr/share/man/man1/rmiregistry-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 80 Nov 21 18:47 servertool -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/servertool
lrwxrwxrwx. 1 root root 84 Nov 21 18:47 servertool.1.gz -> /usr/share/man/man1/servertool-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 79 Nov 21 18:47 tnameserv -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/tnameserv
lrwxrwxrwx. 1 root root 83 Nov 21 18:47 tnameserv.1.gz -> /usr/share/man/man1/tnameserv-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 79 Nov 21 18:47 unpack200 -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/unpack200
lrwxrwxrwx. 1 root root 83 Nov 21 18:47 unpack200.1.gz -> /usr/share/man/man1/unpack200-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
看下手册,的确是一个接口性质的东西
NAME
alternatives - maintain symbolic links determining default commands
SYNOPSIS
alternatives [options] --install link name path priority [--slave link name path]... [--initscript service]
alternatives [options] --remove name path
alternatives [options] --set name path
alternatives [options] --auto name
alternatives [options] --display name
alternatives [options] --config name
alternatives [options] --list name
ok,看下java相关的
# alternatives --display java
java - status is auto.
link currently points to /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/java - priority 1700091
slave ControlPanel: (null)
......
Current `best' version is /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/java.
二、下载安装设置jdk1.8。
首先Java官方下载jdk的rpm包,这个东西方便,如果对默认安装目录不那么在乎的话;另外一个就是.tar.gz包了。
# yum localinstall jdk-8u66-linux-x64.rpm -y /*yum安装,方便*/
看默认安装的目录和其中的文件
# ll /usr/java/
total 8
drwxr-xr-x. 3 root root 51 Dec 2 00:46 .
drwxr-xr-x. 14 root root 4096 Oct 7 08:42 ..
lrwxrwxrwx. 1 root root 16 Dec 2 00:46 default -> /usr/java/latest
drwxr-xr-x. 9 root root 4096 Dec 2 00:46 jdk1.8.0_66
lrwxrwxrwx. 1 root root 21 Dec 2 00:46 latest -> /usr/java/jdk1.8.0_66
如果这个时候来查看java的版本,依然是1.7。也就是说,这个新版本安装并不会去自动更新那个/usr/bin/java或者说是那个alternative的链接目的地;发现没有,这个alternative的作用,应该就是为了版本控制,使得某个软件的多个版本并存并且自定义的切换启用
]# ll /etc/alternatives/ | grep -E "java|jre"
lrwxrwxrwx. 1 root root 38 Dec 2 00:46 appletviewer -> /usr/java/jdk1.8.0_66/bin/appletviewer
lrwxrwxrwx. 1 root root 45 Dec 2 00:46 appletviewer.1 -> /usr/java/jdk1.8.0_66/man/man1/appletviewer.1
lrwxrwxrwx. 1 root root 38 Dec 2 00:46 ControlPanel -> /usr/java/jdk1.8.0_66/bin/ControlPanel
lrwxrwxrwx. 1 root root 34 Dec 2 00:46 extcheck -> /usr/java/jdk1.8.0_66/bin/extcheck
lrwxrwxrwx. 1 root root 41 Dec 2 00:46 extcheck.1 -> /usr/java/jdk1.8.0_66/man/man1/extcheck.1
lrwxrwxrwx. 1 root root 30 Dec 2 00:46 idlj -> /usr/java/jdk1.8.0_66/bin/idlj
lrwxrwxrwx. 1 root root 37 Dec 2 00:46 idlj.1 -> /usr/java/jdk1.8.0_66/man/man1/idlj.1
lrwxrwxrwx. 1 root root 29 Dec 2 00:46 jar -> /usr/java/jdk1.8.0_66/bin/jar
lrwxrwxrwx. 1 root root 36 Dec 2 00:46 jar.1 -> /usr/java/jdk1.8.0_66/man/man1/jar.1
lrwxrwxrwx. 1 root root 35 Dec 2 00:46 jarsigner -> /usr/java/jdk1.8.0_66/bin/jarsigner
lrwxrwxrwx. 1 root root 42 Dec 2 00:46 jarsigner.1 -> /usr/java/jdk1.8.0_66/man/man1/jarsigner.1
lrwxrwxrwx. 1 root root 74 Dec 2 00:46 java -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/java
lrwxrwxrwx. 1 root root 37 Dec 2 00:46 java.1 -> /usr/java/jdk1.8.0_66/man/man1/java.1
lrwxrwxrwx. 1 root root 78 Dec 2 00:46 java.1.gz -> /usr/share/man/man1/java-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 31 Dec 2 00:46 javac -> /usr/java/jdk1.8.0_66/bin/javac
lrwxrwxrwx. 1 root root 38 Dec 2 00:46 javac.1 -> /usr/java/jdk1.8.0_66/man/man1/javac.1
lrwxrwxrwx. 1 root root 33 Dec 2 00:46 javadoc -> /usr/java/jdk1.8.0_66/bin/javadoc
lrwxrwxrwx. 1 root root 40 Dec 2 00:46 javadoc.1 -> /usr/java/jdk1.8.0_66/man/man1/javadoc.1
lrwxrwxrwx. 1 root root 40 Dec 2 00:46 javafxpackager -> /usr/java/jdk1.8.0_66/bin/javafxpackager
lrwxrwxrwx. 1 root root 47 Dec 2 00:46 javafxpackager.1 -> /usr/java/jdk1.8.0_66/man/man1/javafxpackager.1
lrwxrwxrwx. 1 root root 31 Dec 2 00:46 javah -> /usr/java/jdk1.8.0_66/bin/javah
lrwxrwxrwx. 1 root root 38 Dec 2 00:46 javah.1 -> /usr/java/jdk1.8.0_66/man/man1/javah.1
lrwxrwxrwx. 1 root root 31 Dec 2 00:46 javap -> /usr/java/jdk1.8.0_66/bin/javap
lrwxrwxrwx. 1 root root 38 Dec 2 00:46 javap.1 -> /usr/java/jdk1.8.0_66/man/man1/javap.1
lrwxrwxrwx. 1 root root 38 Dec 2 00:46 javapackager -> /usr/java/jdk1.8.0_66/bin/javapackager
lrwxrwxrwx. 1 root root 45 Dec 2 00:46 javapackager.1 -> /usr/java/jdk1.8.0_66/man/man1/javapackager.1
lrwxrwxrwx. 1 root root 38 Dec 2 00:46 java-rmi.cgi -> /usr/java/jdk1.8.0_66/bin/java-rmi.cgi
lrwxrwxrwx. 1 root root 32 Dec 2 00:46 javaws -> /usr/java/jdk1.8.0_66/bin/javaws
lrwxrwxrwx. 1 root root 39 Dec 2 00:46 javaws.1 -> /usr/java/jdk1.8.0_66/man/man1/javaws.1
lrwxrwxrwx. 1 root root 37 Sep 20 09:41 javaws.1.gz -> /usr/share/man/man1/javaws-itweb.1.gz
lrwxrwxrwx. 1 root root 30 Dec 2 00:46 jcmd -> /usr/java/jdk1.8.0_66/bin/jcmd
lrwxrwxrwx. 1 root root 37 Dec 2 00:46 jcmd.1 -> /usr/java/jdk1.8.0_66/man/man1/jcmd.1
lrwxrwxrwx. 1 root root 34 Dec 2 00:46 jconsole -> /usr/java/jdk1.8.0_66/bin/jconsole
lrwxrwxrwx. 1 root root 41 Dec 2 00:46 jconsole.1 -> /usr/java/jdk1.8.0_66/man/man1/jconsole.1
lrwxrwxrwx. 1 root root 34 Dec 2 00:46 jcontrol -> /usr/java/jdk1.8.0_66/bin/jcontrol
lrwxrwxrwx. 1 root root 29 Dec 2 00:46 jdb -> /usr/java/jdk1.8.0_66/bin/jdb
lrwxrwxrwx. 1 root root 36 Dec 2 00:46 jdb.1 -> /usr/java/jdk1.8.0_66/man/man1/jdb.1
lrwxrwxrwx. 1 root root 31 Dec 2 00:46 jdeps -> /usr/java/jdk1.8.0_66/bin/jdeps
lrwxrwxrwx. 1 root root 38 Dec 2 00:46 jdeps.1 -> /usr/java/jdk1.8.0_66/man/man1/jdeps.1
lrwxrwxrwx. 1 root root 30 Dec 2 00:46 jhat -> /usr/java/jdk1.8.0_66/bin/jhat
lrwxrwxrwx. 1 root root 37 Dec 2 00:46 jhat.1 -> /usr/java/jdk1.8.0_66/man/man1/jhat.1
lrwxrwxrwx. 1 root root 31 Dec 2 00:46 jinfo -> /usr/java/jdk1.8.0_66/bin/jinfo
lrwxrwxrwx. 1 root root 38 Dec 2 00:46 jinfo.1 -> /usr/java/jdk1.8.0_66/man/man1/jinfo.1
lrwxrwxrwx. 1 root root 29 Dec 2 00:46 jjs -> /usr/java/jdk1.8.0_66/bin/jjs
lrwxrwxrwx. 1 root root 36 Dec 2 00:46 jjs.1 -> /usr/java/jdk1.8.0_66/man/man1/jjs.1
lrwxrwxrwx. 1 root root 30 Dec 2 00:46 jmap -> /usr/java/jdk1.8.0_66/bin/jmap
lrwxrwxrwx. 1 root root 37 Dec 2 00:46 jmap.1 -> /usr/java/jdk1.8.0_66/man/man1/jmap.1
lrwxrwxrwx. 1 root root 29 Dec 2 00:46 jmc -> /usr/java/jdk1.8.0_66/bin/jmc
lrwxrwxrwx. 1 root root 36 Dec 2 00:46 jmc.1 -> /usr/java/jdk1.8.0_66/man/man1/jmc.1
lrwxrwxrwx. 1 root root 33 Dec 2 00:46 jmc.ini -> /usr/java/jdk1.8.0_66/bin/jmc.ini
lrwxrwxrwx. 1 root root 29 Dec 2 00:46 jps -> /usr/java/jdk1.8.0_66/bin/jps
lrwxrwxrwx. 1 root root 36 Dec 2 00:46 jps.1 -> /usr/java/jdk1.8.0_66/man/man1/jps.1
lrwxrwxrwx. 1 root root 65 Dec 2 00:46 jre -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre
lrwxrwxrwx. 1 root root 65 Nov 21 18:47 jre_1.7.0 -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre
lrwxrwxrwx. 1 root root 69 Nov 21 18:47 jre_1.7.0_exports -> /usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
lrwxrwxrwx. 1 root root 60 Nov 21 18:47 jre_1.7.0_openjdk -> /usr/lib/jvm/jre-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
lrwxrwxrwx. 1 root root 69 Nov 21 18:47 jre_1.7.0_openjdk_exports -> /usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
lrwxrwxrwx. 1 root root 69 Dec 2 00:46 jre_exports -> /usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
lrwxrwxrwx. 1 root root 65 Nov 21 18:47 jre_openjdk -> /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre
lrwxrwxrwx. 1 root root 69 Nov 21 18:47 jre_openjdk_exports -> /usr/lib/jvm-exports/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64
lrwxrwxrwx. 1 root root 36 Dec 2 00:46 jrunscript -> /usr/java/jdk1.8.0_66/bin/jrunscript
lrwxrwxrwx. 1 root root 43 Dec 2 00:46 jrunscript.1 -> /usr/java/jdk1.8.0_66/man/man1/jrunscript.1
lrwxrwxrwx. 1 root root 35 Dec 2 00:46 jsadebugd -> /usr/java/jdk1.8.0_66/bin/jsadebugd
lrwxrwxrwx. 1 root root 42 Dec 2 00:46 jsadebugd.1 -> /usr/java/jdk1.8.0_66/man/man1/jsadebugd.1
lrwxrwxrwx. 1 root root 32 Dec 2 00:46 jstack -> /usr/java/jdk1.8.0_66/bin/jstack
lrwxrwxrwx. 1 root root 39 Dec 2 00:46 jstack.1 -> /usr/java/jdk1.8.0_66/man/man1/jstack.1
lrwxrwxrwx. 1 root root 31 Dec 2 00:46 jstat -> /usr/java/jdk1.8.0_66/bin/jstat
lrwxrwxrwx. 1 root root 38 Dec 2 00:46 jstat.1 -> /usr/java/jdk1.8.0_66/man/man1/jstat.1
lrwxrwxrwx. 1 root root 32 Dec 2 00:46 jstatd -> /usr/java/jdk1.8.0_66/bin/jstatd
lrwxrwxrwx. 1 root root 39 Dec 2 00:46 jstatd.1 -> /usr/java/jdk1.8.0_66/man/man1/jstatd.1
lrwxrwxrwx. 1 root root 35 Dec 2 00:46 jvisualvm -> /usr/java/jdk1.8.0_66/bin/jvisualvm
lrwxrwxrwx. 1 root root 42 Dec 2 00:46 jvisualvm.1 -> /usr/java/jdk1.8.0_66/man/man1/jvisualvm.1
lrwxrwxrwx. 1 root root 33 Dec 2 00:46 keytool -> /usr/java/jdk1.8.0_66/bin/keytool
lrwxrwxrwx. 1 root root 40 Dec 2 00:46 keytool.1 -> /usr/java/jdk1.8.0_66/man/man1/keytool.1
lrwxrwxrwx. 1 root root 81 Dec 2 00:46 keytool.1.gz -> /usr/share/man/man1/keytool-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 27 Sep 20 09:41 libjavaplugin.so.x86_64 -> /usr/lib64/IcedTeaPlugin.so
lrwxrwxrwx. 1 root root 38 Dec 2 00:46 native2ascii -> /usr/java/jdk1.8.0_66/bin/native2ascii
lrwxrwxrwx. 1 root root 45 Dec 2 00:46 native2ascii.1 -> /usr/java/jdk1.8.0_66/man/man1/native2ascii.1
lrwxrwxrwx. 1 root root 30 Dec 2 00:46 orbd -> /usr/java/jdk1.8.0_66/bin/orbd
lrwxrwxrwx. 1 root root 37 Dec 2 00:46 orbd.1 -> /usr/java/jdk1.8.0_66/man/man1/orbd.1
lrwxrwxrwx. 1 root root 78 Dec 2 00:46 orbd.1.gz -> /usr/share/man/man1/orbd-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 33 Dec 2 00:46 pack200 -> /usr/java/jdk1.8.0_66/bin/pack200
lrwxrwxrwx. 1 root root 40 Dec 2 00:46 pack200.1 -> /usr/java/jdk1.8.0_66/man/man1/pack200.1
lrwxrwxrwx. 1 root root 81 Dec 2 00:46 pack200.1.gz -> /usr/share/man/man1/pack200-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 36 Dec 2 00:46 policytool -> /usr/java/jdk1.8.0_66/bin/policytool
lrwxrwxrwx. 1 root root 43 Dec 2 00:46 policytool.1 -> /usr/java/jdk1.8.0_66/man/man1/policytool.1
lrwxrwxrwx. 1 root root 30 Dec 2 00:46 rmic -> /usr/java/jdk1.8.0_66/bin/rmic
lrwxrwxrwx. 1 root root 37 Dec 2 00:46 rmic.1 -> /usr/java/jdk1.8.0_66/man/man1/rmic.1
lrwxrwxrwx. 1 root root 30 Dec 2 00:46 rmid -> /usr/java/jdk1.8.0_66/bin/rmid
lrwxrwxrwx. 1 root root 37 Dec 2 00:46 rmid.1 -> /usr/java/jdk1.8.0_66/man/man1/rmid.1
lrwxrwxrwx. 1 root root 78 Dec 2 00:46 rmid.1.gz -> /usr/share/man/man1/rmid-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 37 Dec 2 00:46 rmiregistry -> /usr/java/jdk1.8.0_66/bin/rmiregistry
lrwxrwxrwx. 1 root root 44 Dec 2 00:46 rmiregistry.1 -> /usr/java/jdk1.8.0_66/man/man1/rmiregistry.1
lrwxrwxrwx. 1 root root 85 Dec 2 00:46 rmiregistry.1.gz -> /usr/share/man/man1/rmiregistry-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 35 Dec 2 00:46 schemagen -> /usr/java/jdk1.8.0_66/bin/schemagen
lrwxrwxrwx. 1 root root 42 Dec 2 00:46 schemagen.1 -> /usr/java/jdk1.8.0_66/man/man1/schemagen.1
lrwxrwxrwx. 1 root root 35 Dec 2 00:46 serialver -> /usr/java/jdk1.8.0_66/bin/serialver
lrwxrwxrwx. 1 root root 42 Dec 2 00:46 serialver.1 -> /usr/java/jdk1.8.0_66/man/man1/serialver.1
lrwxrwxrwx. 1 root root 36 Dec 2 00:46 servertool -> /usr/java/jdk1.8.0_66/bin/servertool
lrwxrwxrwx. 1 root root 43 Dec 2 00:46 servertool.1 -> /usr/java/jdk1.8.0_66/man/man1/servertool.1
lrwxrwxrwx. 1 root root 84 Dec 2 00:46 servertool.1.gz -> /usr/share/man/man1/servertool-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 35 Dec 2 00:46 tnameserv -> /usr/java/jdk1.8.0_66/bin/tnameserv
lrwxrwxrwx. 1 root root 42 Dec 2 00:46 tnameserv.1 -> /usr/java/jdk1.8.0_66/man/man1/tnameserv.1
lrwxrwxrwx. 1 root root 83 Dec 2 00:46 tnameserv.1.gz -> /usr/share/man/man1/tnameserv-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 35 Dec 2 00:46 unpack200 -> /usr/java/jdk1.8.0_66/bin/unpack200
lrwxrwxrwx. 1 root root 42 Dec 2 00:46 unpack200.1 -> /usr/java/jdk1.8.0_66/man/man1/unpack200.1
lrwxrwxrwx. 1 root root 83 Dec 2 00:46 unpack200.1.gz -> /usr/share/man/man1/unpack200-java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64.1.gz
lrwxrwxrwx. 1 root root 31 Dec 2 00:46 wsgen -> /usr/java/jdk1.8.0_66/bin/wsgen
lrwxrwxrwx. 1 root root 38 Dec 2 00:46 wsgen.1 -> /usr/java/jdk1.8.0_66/man/man1/wsgen.1
lrwxrwxrwx. 1 root root 34 Dec 2 00:46 wsimport -> /usr/java/jdk1.8.0_66/bin/wsimport
lrwxrwxrwx. 1 root root 41 Dec 2 00:46 wsimport.1 -> /usr/java/jdk1.8.0_66/man/man1/wsimport.1
lrwxrwxrwx. 1 root root 29 Dec 2 00:46 xjc -> /usr/java/jdk1.8.0_66/bin/xjc
lrwxrwxrwx. 1 root root 36 Dec 2 00:46 xjc.1 -> /usr/java/jdk1.8.0_66/man/man1/xjc.1
发现了1.8的身影,具体点看下java的链接
# alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
*+ 1 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.91-2.6.2.1.el7_1.x86_64/jre/bin/java
2 /usr/java/jdk1.8.0_66/jre/bin/java
Enter to keep the current selection[+], or type selection number:
哦哦,这里可以设置更改为第二个,也就是1.8版本的。
# java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)
再来核实下一开始就发现的两个链接,发现的确只是更改了alternative中的链接目的地
# ll /usr/bin/java
lrwxrwxrwx. 1 root root 22 Dec 2 05:41 /usr/bin/java -> /etc/alternatives/java
# ll /etc/alternatives/java
lrwxrwxrwx. 1 root root 34 Dec 2 05:41 /etc/alternatives/java -> /usr/java/jdk1.8.0_66/jre/bin/java
那么其他的地方会自动的跟随上面的切换而自动切换么?核实下
# ll /etc/alternatives/jar
lrwxrwxrwx. 1 root root 29 Dec 2 00:46 /etc/alternatives/jar -> /usr/java/jdk1.8.0_66/bin/jar
# ll /etc/alternatives/javac
lrwxrwxrwx. 1 root root 31 Dec 2 00:46 /etc/alternatives/javac -> /usr/java/jdk1.8.0_66/bin/javac
# ll /etc/alternatives/jconsole
lrwxrwxrwx. 1 root root 34 Dec 2 00:46 /etc/alternatives/jconsole -> /usr/java/jdk1.8.0_66/bin/jconsole
# ll /etc/alternatives/jcmd
lrwxrwxrwx. 1 root root 30 Dec 2 00:46 /etc/alternatives/jcmd -> /usr/java/jdk1.8.0_66/bin/jcmd
jar和javac都自动跟随切换了,所以到此我可以认为,一切都就绪不需要额外的人工设置了。
所以整个从1.7到1.8的升级过程为下面简单两步:
1. 下载1.8的rpm包并yum安装
2. # alternatives --config java来切换为新版本
另外,alternatives还有个操作是--install,在手工安装例如tar.gz包的时候,就可以去手动添加并全局切换/etc/alternatives/java链接。类似地,可以用alternatives来混搭升级安装的Phthon3(CentOS7默认的还是2.7),见下面的脚本,默认就启用了Python3:
if [ $(ls /usr/bin/python* | grep -c python2) -ge 1 ]; then
python_old_version=$(ls -l /usr/bin/python* | grep '/usr/bin/python2 -> ' | awk '{print $11}' | awk -F python '{print $2}')
alternatives --install /usr/bin/python python /usr/bin/python${python_old_version} 1
alternatives --install /usr/bin/python python /usr/local/bin/python3.5 2
# Keep python2 for /usr/bin/yum and /usr/libexec/urlgrabber-ext-down (firewalld not compatible with python3)
sed -i "s@^#\!/usr/bin/python@#\!/usr/bin/python${python_old_version}@" /usr/bin/yum
sed -i "s@^#\! /usr/bin/python@#\! /usr/bin/python${python_old_version}@" /usr/libexec/urlgrabber-ext-down
fi
而如果是去直接更改/usr/bin/java的链接,那就搞麻烦了,如此就会忽略掉alternative的用处不太好去统一管理。至于诸如下面这种修改/etc/profile的方法,不推荐使用 - 麻烦!
# vim /etc/profile
export JAVA_HOME=/path/to/java_version_dir
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JRE_HOME/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH