一、添加如下代码:
[root@mysql-b ~]# cat << EOF >> /etc/profile
##jdk1.8.0_11
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:
J
A
V
A
_
H
O
M
E
/
l
i
b
/
d
t
.
j
a
r
:
JAVA\_HOME/lib/dt.jar:
JAVA_HOME/lib/dt.jar:JAVA_HOME/lib/tools.jar
export PATH=
J
A
V
A
_
H
O
M
E
/
b
i
n
:
JAVA\_HOME/bin:
JAVA_HOME/bin:PATH
[root@mysql-b ~]# ll /usr/bin/java
lrwxrwxrwx. 1 root root 22 9月 13 2017 /usr/bin/java -> /etc/alternatives/java
[root@mysql-b ~]#
[root@mysql-b ~]#
[root@mysql-b ~]# ll /etc/alternatives/java
lrwxrwxrwx. 1 root root 46 9月 13 2017 /etc/alternatives/java -> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
[root@mysql-b ~]#
[root@mysql-b ~]# alternatives --install /usr/bin/java java /usr/local/jdk/java 500
###注意: /usr/local/jdk JDK的文件目录,后面参数可随意
[root@mysql-b ~]# alternatives --config java
共有 3 个程序提供“java”。
选择 命令
-----------------------------------------------
*+ 1 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
2 /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
3 /usr/local/jdk/java
按 Enter 来保存当前选择[+],或键入选择号码: 3
[root@mysql-b ~]#
[root@mysql-b ~]# java -version
java version “1.8.0_11”
Java™ SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot™ 64-Bit Server VM (build 25.11-b03, mixed mode)