Ubuntu 11.04自帶有默認的OpenJDK,雖然網上很多文章說OpenJDK和Sun的JDK沒什麼區別,但以防萬一,還是用官方的吧。
第一步,安裝Sun的JDK:
sudo apt-get install sun-java6-jre
sudo apt-get install sun-java6-jdk
此時,在命令行裡面輸入java -version,顯示的JDK仍然是OpenJDK,所以需要修改默認的JDK
第二步,修改默認JDK
sudo update-alternatives --config java
此時,命令行中會提示你選擇合適的JDK,如
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-6-sun/jre/bin/java 63 manual mode
Press enter to keep the current choice[*], or type selection number: 2
選擇java-6-sun後,再輸入java -version,就會顯示Sun的JDK信息了