Ubuntu12.04 配置JDK7

一. 下载JDK

下载地址在这里http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u4-downloads-1591156.html

二. 解压安装

sudo tar zxvf ./jdk-7u4-linux-i586.tar.gz -C /usr/lib/jvm
cd /usr/lib/jvm
sudo mv jdk1.7.0_04/ java-7-sun

三. 配置环境变量

vi ~/.bashrc 

添加:

export JAVA_HOME=/usr/lib/jvm/java-7-sun
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

保存退出,执行

source ~/.bashrc 

使之生效

四. 由于系统中可能存在OpenJDK,需要将上面安装的JDK设为默认版本(当然卸载OpenJDK也行)

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-7-sun/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-7-sun/bin/javac 300
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/java-7-sun/bin/jar 300 
sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/java-7-sun/bin/javah 300 
sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/java-7-sun/bin/javap 300 
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-i386/jre/bin/java 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk-i386/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-7-sun/bin/java 300 manual mode

Press enter to keep the current choice[*], or type selection number: 

此处,输入2,回车,即可。

五. 测试当前JDK版本

java -version

java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) Server VM (build 23.0-b21, mixed mode)

posted @ 2012-05-14 22:32  漂木  阅读(1327)  评论(0编辑  收藏  举报