On Ubuntu 12.04 LTS。

查 OS 是 32-bit or 64-bit
# file /sbin/init
/sbin/init: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x07075fcb55b05aeb6286efabba63534fa6ecd213, stripped


移除系統安裝的 openjdk
# sudo apt-get purge openjdk-\*

使用 wget 下載 JDK
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-i586.tar.gz


安裝 Java
# sudo mkdir -p /usr/local/java
# sudo cp -r ~/jdk-7u51-linux-i586.tar.gz /usr/local/java/
# cd /usr/local/java
# sudo tar zxvf jdk-7u51-linux-i586.tar.gz

設定路徑
# sudo vi /etc/profile
JAVA_HOME=/usr/local/java/jdk1.7.0_51
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH


設定 Java 環境變數
# sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_51/bin/java" 1
update-alternatives: 以 /usr/local/java/jdk1.7.0_51/bin/java 提供 自動模式 內的 /usr/bin/java (java)

# sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_51/bin/javac" 1
update-alternatives: 以 /usr/local/java/jdk1.7.0_51/bin/javac 提供 自動模式 內的 /usr/bin/javac (javac)

# sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.7.0_51/bin/javaws" 1

將 1.7.0_51 版本設為預設版本
# sudo update-alternatives --set java /usr/local/java/jdk1.7.0_51/bin/java
# sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_51/bin/javac
# sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_51/bin/javaws

查看 Java 版本
# java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode)

flyfox 發表在 痞客邦 PIXNET 留言(0) 人氣()