Install and setup JDK 1.6 for Ubuntu 14.04


先從Oracle下載JDK

解壓縮JDK
chmod +x jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin
sudo mv jdk1.6.0_45 /usr/lib/jvm/

設定所需要的工具

最後的參數32767是priority,數值較大的會優先被使用
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.6.0_45/bin/javac 32767
sudo update-alternatives --install /usr/bin/java  java  /usr/lib/jvm/jdk1.6.0_45/bin/java  32767
sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk1.6.0_45/bin/javah 32767
sudo update-alternatives --install /usr/bin/javadoc   javadoc   /usr/lib/jvm/jdk1.6.0_45/bin/javadoc   32767
sudo update-alternatives --install /usr/bin/javap     javap     /usr/lib/jvm/jdk1.6.0_45/bin/javap     32767
sudo update-alternatives --install /usr/bin/jar       jar       /usr/lib/jvm/jdk1.6.0_45/bin/jar       32767
sudo update-alternatives --install /usr/bin/jarsigner jarsigner /usr/lib/jvm/jdk1.6.0_45/bin/jarsigner 32767
sudo update-alternatives --install /usr/bin/keytool keytool /usr/lib/jvm/jdk1.6.0_45/bin/keytool 32767

互動式設定
如果不確定上面設定的結果是否正確可以用互動式的設定方式,會顯示目前已經有的設定
sudo update-alternatives --config javac
sudo update-alternatives --config java
sudo update-alternatives --config javah
sudo update-alternatives --config javadoc
sudo update-alternatives --config javap
sudo update-alternatives --config jar
sudo update-alternatives --config jarsigner
sudo update-alternatives --config keytool

顯示目前的設置
sudo update-alternatives --display java
sudo update-alternatives --display javac
sudo update-alternatives --display javah
sudo update-alternatives --display javadoc
sudo update-alternatives --display javap
sudo update-alternatives --display jar
sudo update-alternatives --display jarsigner
sudo udpate-alternatives --display keytool

留言