Ubuntu 10.04 server 安装 sun-java

有一批机器默认安装的是 openjdk,现在需要安装 sun-java-jdk。即先卸载后安装。
网上很多的说法是添加下面的源:
deb http://archive.canonical.com/ lucid partner

然后 update:
$ sudo aptitude update

但是并没有找到 sun 的包:
$ sudo apt-cache search sun-java6-jdk

G 了下,sun 的包已经被移到 ppa 里面去了:
$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:sun-java-community-team/sun-java6
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk


安装完了查看版本,发现依然是 openjdk 的:
$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.13) (6b20-1.9.13-0ubuntu1~10.04.1)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
$ which java
/usr/bin/java
$ ll /usr/bin/java
lrwxrwxrwx 1 root root 22 2012-03-11 00:10 /usr/bin/java -> /etc/alternatives/java
$ ll /etc/alternatives/java
lrwxrwxrwx 1 root root 40 2012-03-11 00:10 /etc/alternatives/java -> /usr/lib/jvm/java-6-openjdk/jre/bin/ja

可以直接卸载掉 openjdk:
$ sudo apt-get remove openjdk-6-jdk --purge -y
$ sudo apt-get autoremove

卸载软件包是有一定风险的,保守做法可以将 sun-java 设置为 "default":
$ sudo update-alternatives --config java
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
update-alternatives: using /usr/lib/jvm/java-6-sun/jre/bin/java to provide /usr/bin/java (java) in manual mode.

$ ll /etc/alternatives/java
lrwxrwxrwx 1 root root 36 2012-03-11 00:11 /etc/alternatives/java -> /usr/lib/jvm/java-6-sun/jre/bin/java
$ java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b16, mixed mode)

或者直接运行:
$ sudo update-java-alternatives -s java-6-sun