2013年11月4日 星期一

[研究] Java 6 , 7 安裝差異+選擇切換研究 (CentOS 6.4 x64)

[研究] Java 7 安裝差異+選擇切換研究 (CentOS 6.4 x64)

2013-11-04
2013-12-04 修訂

一、Oracle Java Runtime -  JRE 7 Update 45 安裝差異

檔案包含
jre-7u45-linux-x64.rpm
jre-7u45-linux-x64.tar.gz

檔案請自己到官方網站下載
http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html#javasejdk

先看一下目前情況

[root@localhost ~]# find / -name java
/etc/alternatives/java
/etc/java
/etc/pki/java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/bin/java
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java
/usr/lib/java
/usr/bin/java
/usr/share/java
/usr/lib64/libreoffice/ure/share/java
/usr/lib64/libreoffice/basis3.4/share/Scripts/java
/var/lib/alternatives/java
[root@localhost ~]#

安裝測試 jre-7u45-linux-x64.rpm

[root@localhost ~]# rpm -ivh jre-7u45-linux-x64.rpm
[root@localhost ~]# find / -name java
/etc/alternatives/java
/etc/java
/etc/pki/java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/bin/java
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java
/usr/lib/java
/usr/java
/usr/java/jre1.7.0_45/bin/java
/usr/bin/java
/usr/share/java
/usr/lib64/libreoffice/ure/share/java
/usr/lib64/libreoffice/basis3.4/share/Scripts/java
/var/lib/alternatives/java
[root@localhost ~]#

[root@localhost java]# export | grep JAVA
[root@localhost java]#

[root@localhost java]# ls /usr/java/jre1.7.0_45/
bin  COPYRIGHT  lib  LICENSE  man  plugin  README  release  THIRDPARTYLICENSEREADME-JAVAFX.txt  THIRDPARTYLICENSEREADME.txt  Welcome.html

安裝測試 jre-7u45-linux-x64.tar.gz

敝人把檔案解壓放到 /usr/local 目錄

[root@localhost ~]# tar zxvf jre-7u45-linux-x64.tar.gz -C /usr/local
[root@localhost ~]# find / -name java
/etc/alternatives/java
/etc/java
/etc/pki/java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/bin/java
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java
/usr/lib/java
/usr/local/jre1.7.0_45/bin/java
/usr/java
/usr/java/jre1.7.0_45/bin/java
/usr/bin/java
/usr/share/java
/usr/lib64/libreoffice/ure/share/java
/usr/lib64/libreoffice/basis3.4/share/Scripts/java
/var/lib/alternatives/java
[root@localhost ~]#

[root@localhost java]# ls /usr/local/jre1.7.0_45
bin  COPYRIGHT  lib  LICENSE  man  plugin  README  release  THIRDPARTYLICENSEREADME-JAVAFX.txt  THIRDPARTYLICENSEREADME.txt  Welcome.html

也就是 jre-7u45-linux-x64.rpm 把檔案安裝到 /usr/java/jre1.7.0_45/ 目錄
也就是 jre-7u45-linux-x64.tar.gz 把檔案安裝到你選定目錄下的 jre1.7.0_45 目錄中,本範例為 /usr/local/jre1.7.0_45

二、切換 Java

有時候,可能需用到特定版本 Java,或特定種類的 Java,此時可以設定預設的選擇。

顯示目前 Java 版本

[root@localhost ~]# java -version
java version "1.7.0_09-icedtea"
OpenJDK Runtime Environment (rhel-2.3.4.1.el6_3-x86_64)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)
[root@localhost ~]#

顯示電腦中可選擇切換的 Java 版本 (前面有 + 表示目前選定的)

[root@localhost ~]# alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 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

Enter to keep the current selection[+], or type selection number:
[root@localhost ~]#

把 /usr/java/jre1.7.0_45/bin/java 加入選單中,優先權 100 (隨便給個值吧)

[root@localhost ~]# alternatives --install /usr/bin/java java /usr/java/jre1.7.0_45/bin/java 100

切換預設的 Java

[root@localhost ~]# alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 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/java/jre1.7.0_45/bin/java

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

確認一下目前的版本

[root@localhost ~]# 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)
[root@localhost ~]#

顯示一下目前的選擇 (選擇號碼直接按下 Enter )

[root@localhost java]# alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*  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/java/jre1.7.0_45/bin/java

Enter to keep the current selection[+], or type selection number:
[root@localhost java]#

*****************************************************************************

因為測試是在虛擬機器上測試的,把快照復原後,改測試 JDK,比較和 JRE 差異 (不直接前面繼續做,是避免有些目錄檔案重複使用,看不出差異)

jdk-7u45-linux-x64.rpm

三、安裝測試 jdk-7u45-linux-x64.rpm


[root@localhost ~]# rpm -ivh jdk-7u45-linux-x64.rpm

[root@localhost ~]# find / -name java
/etc/alternatives/java
/etc/java
/etc/pki/java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/bin/java
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java
/usr/lib/java
/usr/java
/usr/java/jdk1.7.0_45/jre/bin/java
/usr/java/jdk1.7.0_45/bin/java
/usr/bin/java
/usr/share/java
/usr/lib64/libreoffice/ure/share/java
/usr/lib64/libreoffice/basis3.4/share/Scripts/java
/var/lib/alternatives/java
[root@localhost ~]#

也就是只單獨安裝 JRE 時候,JRE 會安裝到
/usr/java/jre1.7.0_45/bin/java

但是安裝 JDK 時候,JRE 會安裝到
/usr/java/jdk1.7.0_45/jre/bin/java

四、歸納結論


JRE 6 Update 45 =>  JRE 7 Update 45

jre-6u45-linux-i586.bin jre-7u45-linux-i586.tar.gz
jre-6u45-linux-i586-rpm.bin jre-7u45-linux-i586.rpm

jre-6u45-linux-x64.bin jre-7u45-linux-x64.tar.gz
jre-6u45-linux-x64-rpm.bin jre-7u45-linux-x64.rpm

jre-6u45-windows-i586.exe jre-7u45-windows-i586.exe
jdk-6u45-windows-x64.exe jre-7u45-windows-x64.exe

JDK 6 Update 45 =>  JDK 7 Update 45

jdk-6u45-linux-i586.bin jdk-7u45-linux-i586.tar.gz
jdk-6u45-linux-i586-rpm.bin jdk-7u45-linux-i586.rpm

jdk-6u45-linux-x64.bin jdk-7u45-linux-x64.tar.gz
(解壓到 ./jdk1.6.0_45/ 目錄)   (解壓到 ./jre1.7.0_45/ 目錄)  
jdk-6u45-linux-x64-rpm.bin jdk-7u45-linux-x64.rpm
(安裝到 /usr/java/jdk1.6.0_45/ 目錄)    (安裝到 /usr/java/jdk1.7.0_45/ 目錄)  

jdk-6u45-windows-i586.exe jdk-7u45-windows-i586.exe
jdk-6u45-windows-x64.exe jdk-7u45-windows-x64

沒有這種包裝 =>  Server JRE 7 Update 45

                server-jre-7u45-linux-x64.tar.gz
                server-jre-7u45-windows-x64.tar.gz

Java 6 for Linux 版本都是 .bin,Java 7 for Linux 版本變成 tar.gz 或 .rpm
for Linux 版本,只要檔名有 rpm,就會安裝到 /usr/java 目錄,否則會解壓到本目錄

for Windows 版本,檔案規則沒有甚麼變化。


五、下載

Oracle JAVA 下載目錄 (目前只有 Java 7,以前 Java 6 和 Java 7 同時提供)
http://www.oracle.com/technetwork/java/javase/downloads/index.html

Oracle Java 6 各版本下載必須到這裡
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html


六、用 wget 下載

參考這篇
https://ivan-site.com/2012/05/download-oracle-java-jre-jdk-using-a-script/

用下面指令可以不透過網頁下載
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" "http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin"

但是檔案名稱會是
jdk-6u45-linux-x64.bin?AuthParam=1386128533_c43176bf92ecc95fde2480413e27ec3d

小弟添加  -O  jdk-6u45-linux-x64.bin  參數,指定輸出檔案

wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" "http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin"  -O  jdk-6u45-linux-x64.bin

可以直接下載到

jdk-6u45-linux-x64.bin

(完)

沒有留言:

張貼留言