一、添加如下代码:
[root@mysql-b ~]# cat << EOF >> /etc/profile
##jdk1.8.0_11
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$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(TM) SE Runtime Environment (build 1.8.0_11-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.11-b03, mixed mode)
Logo

更多推荐