2013年12月26日 星期四

[研究] Oracle Java 7 Update 45 手動安裝與快速安裝程式 (CentOS 6.5 x64)

[研究] Oracle Java 7 Update 45 手動安裝與快速安裝程式 (CentOS 6.5 x64)

2013-12-26

一、手動安裝

[root@localhost ~]# 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/7u45-b18/jdk-7u45-linux-x64.rpm"  -O  jdk-7u45-linux-x64.rpm

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

[root@localhost ~]# find / -name java
/usr/bin/java
/usr/lib/java
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.45.x86_64/jre/bin/java
/usr/lib64/libreoffice/ure/share/java
/usr/lib64/libreoffice/share/Scripts/java
/usr/java
/usr/java/jdk1.7.0_45/bin/java
/usr/java/jdk1.7.0_45/jre/bin/java
/usr/share/java
/usr/share/doc/db4-devel-4.7.25/ref/java
/usr/share/doc/db4-devel-4.7.25/java
/etc/alternatives/java
/etc/pki/java
/etc/pki/ca-trust/extracted/java
/etc/java
/var/lib/alternatives/java

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

設定預設的 Java

[root@localhost ~]# alternatives --set  java /usr/java/jdk1.7.0_45/bin/java

[root@localhost ~]# alternatives --config java
alternatives --display 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/jdk1.7.0_45/bin/java

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

讓 reboot 或再次登入後,環境變數自動生效

[root@localhost ~]# vi /etc/profile

最後面加上
export JAVA_HOME=/usr/java/jdk1.7.0_45
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar

載入 /etc/profile 設定

[root@localhost ~]# source /etc/profile

確認目前版本

[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 ~]#

不過發現 alternatives 建議使用 OpenJDK,而非剛安裝的 Oracle JDK

[root@localhost ~]# alternatives --display java
java - status is manual.
 link currently points to /usr/java/jdk1.7.0_45/bin/java
/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java - priority 170045
 slave keytool: /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/keytool
 slave orbd: /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/orbd
 slave pack200: /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/pack200
 slave rmid: /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/rmid
 slave rmiregistry: /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/rmiregistry
 slave servertool: /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/servertool
 slave tnameserv: /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/tnameserv
 slave unpack200: /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/unpack200
 slave jre_exports: /usr/lib/jvm-exports/jre-1.7.0-openjdk.x86_64
 slave jre: /usr/lib/jvm/jre-1.7.0-openjdk.x86_64
 slave java.1.gz: /usr/share/man/man1/java-java-1.7.0-openjdk.1.gz
 slave keytool.1.gz: /usr/share/man/man1/keytool-java-1.7.0-openjdk.1.gz
 slave orbd.1.gz: /usr/share/man/man1/orbd-java-1.7.0-openjdk.1.gz
 slave pack200.1.gz: /usr/share/man/man1/pack200-java-1.7.0-openjdk.1.gz
 slave rmid.1.gz: /usr/share/man/man1/rmid-java-1.7.0-openjdk.1.gz
 slave rmiregistry.1.gz: /usr/share/man/man1/rmiregistry-java-1.7.0-openjdk.1.gz
 slave servertool.1.gz: /usr/share/man/man1/servertool-java-1.7.0-openjdk.1.gz
 slave tnameserv.1.gz: /usr/share/man/man1/tnameserv-java-1.7.0-openjdk.1.gz
 slave unpack200.1.gz: /usr/share/man/man1/unpack200-java-1.7.0-openjdk.1.gz
/usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java - priority 16000
 slave keytool: /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/keytool
 slave orbd: /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/orbd
 slave pack200: /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/pack200
 slave rmid: /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/rmid
 slave rmiregistry: /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/rmiregistry
 slave servertool: /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/servertool
 slave tnameserv: /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/tnameserv
 slave unpack200: /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/unpack200
 slave jre_exports: /usr/lib/jvm-exports/jre-1.6.0-openjdk.x86_64
 slave jre: /usr/lib/jvm/jre-1.6.0-openjdk.x86_64
 slave java.1.gz: /usr/share/man/man1/java-java-1.6.0-openjdk.1.gz
 slave keytool.1.gz: /usr/share/man/man1/keytool-java-1.6.0-openjdk.1.gz
 slave orbd.1.gz: /usr/share/man/man1/orbd-java-1.6.0-openjdk.1.gz
 slave pack200.1.gz: /usr/share/man/man1/pack200-java-1.6.0-openjdk.1.gz
 slave rmid.1.gz: /usr/share/man/man1/rmid-java-1.6.0-openjdk.1.gz
 slave rmiregistry.1.gz: /usr/share/man/man1/rmiregistry-java-1.6.0-openjdk.1.gz
 slave servertool.1.gz: /usr/share/man/man1/servertool-java-1.6.0-openjdk.1.gz
 slave tnameserv.1.gz: /usr/share/man/man1/tnameserv-java-1.6.0-openjdk.1.gz
 slave unpack200.1.gz: /usr/share/man/man1/unpack200-java-1.6.0-openjdk.1.gz
/usr/java/jdk1.7.0_45/bin/java - priority 100
 slave keytool: (null)
 slave orbd: (null)
 slave pack200: (null)
 slave rmid: (null)
 slave rmiregistry: (null)
 slave servertool: (null)
 slave tnameserv: (null)
 slave unpack200: (null)
 slave jre_exports: (null)
 slave jre: (null)
 slave java.1.gz: (null)
 slave keytool.1.gz: (null)
 slave orbd.1.gz: (null)
 slave pack200.1.gz: (null)
 slave rmid.1.gz: (null)
 slave rmiregistry.1.gz: (null)
 slave servertool.1.gz: (null)
 slave tnameserv.1.gz: (null)
 slave unpack200.1.gz: (null)
Current `best' version is /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java.
[root@localhost ~]#


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

二、自動下載安裝程式

執行方法,請先切換成 root 後執行

[root@localhost ~]# su  root
[root@localhost ~]# vi  JDK7U45x64_Install.sh
把下面框中內容全部貼上
[root@localhost ~]# chmod +x  JDK7U45x64_Install.sh
[root@localhost ~]# ./JDK7U45x64_Install.sh

注意:請勿把下面程式直接貼到命令提示 (例如:[root@localhost ~]#  ) 下直接執行,不然 if then ... else if 這類不是單一行命令的程式會執行錯誤。內容

JDK7U45x64_Install.sh 內容如下:

#!/bin/bash

echo -e "\033[31m"
echo -e "Program : JDK7U45x64_Install.sh "
echo -e "JDK 7 Update 45 x86_64 Install Shell Script (CentOS 6.5 x86_64) "
echo -e "by Shau-Rong Lu 2013/12/26 "
echo -e "\033[0m"

cd /usr/local

if [ ! -s jdk-7u45-linux-x64.rpm ]; then
  echo "Can not find /usr/local/jdk-7u45-linux-x64.rpm"
  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/7u45-b18/jdk-7u45-linux-x64.rpm"  -O  jdk-7u45-linux-x64.rpm
  #exit
fi

rpm -ivh jdk-7u45-linux-x64.rpm
alternatives --install /usr/bin/java  java  /usr/java/jdk1.7.0_45/bin/java  100
alternatives --set  java /usr/java/jdk1.7.0_45/bin/java

echo

echo 'export JAVA_HOME=/usr/java/jdk1.7.0_45' >> /etc/profile
echo 'export PATH=$PATH:$JAVA_HOME/bin' >> /etc/profile
echo 'export CLASSPATH=$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar' >> /etc/profile

source /etc/profile

java -version

export | grep jdk

實際測試

[root@localhost ~]# ./JDK7U45x64_Install.sh

Program : JDK7U45x64_Install.sh
JDK 7 Update 45 x86_64 Install Shell Script (CentOS 6.5 x86_64)
by Shau-Rong Lu 2013/12/26

Can not find /usr/local/jdk-7u45-linux-x64.rpm
--2013-12-07 09:25:38--  http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-x64.rpm
Resolving download.oracle.com... 42.99.128.177, 42.99.128.147
Connecting to download.oracle.com|42.99.128.177|:80... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://edelivery.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-x64.rpm [following]
--2013-12-07 09:25:38--  https://edelivery.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-x64.rpm
Resolving edelivery.oracle.com... 23.37.150.140
Connecting to edelivery.oracle.com|23.37.150.140|:443... connected.
WARNING: certificate common name “www.oracle.comâ€edelivery.oracle.comâ€
                                                                          HTTP request sent, awaiting response... 302 Moved Temporarily
Location: http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-x64.rpm?AuthParam=1388037001_e82f70b1616cf2d5293591ec1f666bb1 [following]
--2013-12-07 09:25:39--  http://download.oracle.com/otn-pub/java/jdk/7u45-b18/jdk-7u45-linux-x64.rpm?AuthParam=1388037001_e82f70b1616cf2d5293591ec1f666bb1
Reusing existing connection to download.oracle.com:80.
HTTP request sent, awaiting response... 200 OK
Length: 122585894 (117M) [application/x-redhat-package-manager]
Saving to: “jdk-7u45-linux-x64.rpmâ€

100%[========================================================================================================================================>] 122,585,894  829K/s   in 2m 27s

2013-12-07 09:28:06 (816 KB/s) - “jdk-7u45-linux-x64.rpmâ€

Preparing...                ########################################### [100%]
        package jdk-2000:1.7.0_45-fcs.x86_64 is already installed

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)
declare -x CLASSPATH="/usr/java/jdk1.7.0_45/jre/lib/ext:/usr/java/jdk1.7.0_45/lib/tools.jar"
declare -x JAVA_HOME="/usr/java/jdk1.7.0_45"
declare -x PATH="/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/java/jdk1.7.0_45/bin:/usr/java/jdk1.7.0_45/bin"
[root@localhost ~]#

(完)

沒有留言:

張貼留言