在Ubuntu上安装Oracle JDK

Posted by Elton's Blog on January 13, 2013

如果不想使用Ubuntu提供的OpenJDK,想使用Oracle的版本。可以进行如下操作

  1. 解压下载的jdk压缩包
tar xvzf jdk-7u10-linux-x64.tar.gz 
  1. 移动到系统lib目录
sudo mv ./jdk1.7.0_10 /usr/lib/jvm/jdk1.7.0
  1. 更新系统
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
  1. 配置系统
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-7-openjdk-amd64/jre/bin/java   1071      auto mode
  1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
  2            /usr/lib/jvm/jdk1.7.0/bin/java                   1         manual mode
Press enter to keep the current choice[*], or type selection number: 2

选择刚刚配置的jdk。 类似再操作

sudo update-alternatives --config javac

之后,就可以使用java -version检测一下是否安装正确了。