2015年2月2日 星期一

CentOS 更新Java JDK 版本

終於得開始碰Java~
雖然一開始都是拿Sample Code 所以1.7就夠用了~
但當要自己寫的時候,還是希望用最新的 ^.^

1.查看目前版本~
[training@tiger ~]$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)



2.下載最新版本Java SE RPM



3.移到下載目錄下,用rpm安裝~
[training@tiger software]$ cd /home/training/Downloads/
[training@tiger Downloads]$ sudo rpm -ivh jdk-8u31-linux-x64.rpm 
Preparing...                ########################################### [100%]
   1:jdk1.8.0_31            ########################################### [100%]
Unpacking JAR files...
 rt.jar...
 jsse.jar...
 charsets.jar...
 tools.jar...
 localedata.jar...
 jfxrt.jar...
[training@tiger Downloads]$ ls li /usr/java/
default  jdk1.6.0_31  jdk1.7.0_45-cloudera  jdk1.8.0_31  latest

4.設置環境變數 /etc/profile 在最後加上
export JAVA_HOME=/usr/java/latest
export JRE_HOME=/usr/java/latest/jre
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$CLASSPATH:.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib

5.修改預設jdk
[training@tiger ~]$ sudo update-alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_31/bin/java 300
[training@tiger ~]$ sudo update-alternatives --install /usr/bin/javac javac /usr/java/jdk1.8.0_31/bin/javac 300
[training@tiger ~]$ sudo update-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/java/jdk1.7.0_45-cloudera/bin/java
   3           /usr/java/jdk1.8.0_31/bin/java

Enter to keep the current selection[+], or type selection number: 3
[training@tiger ~]$ sudo update-alternatives --config javac

There are 2 programs which provide 'javac'.

  Selection    Command
-----------------------------------------------
 + 1           /usr/java/jdk1.7.0_45-cloudera/bin/javac
*  2           /usr/java/jdk1.8.0_31/bin/javac

Enter to keep the current selection[+], or type selection number: 2


6.重load /etc/profile 並確定版本
[training@tiger ~]$ source /etc/profile
[training@tiger ~]$ java -version
java version "1.8.0_31"
Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)


OK了~