Ubuntu 12.10 安装 JDK1.7.0_15

1. 打开官网下载Java安装文件

jdk-7u15-linux-x64.tar.gz

 2.打开终端,根据个人习惯建立目录

sudo mkdir /usr/local/development

 3.将下载的文件移动到这个文件夹下面并进行解压。使用如下命令:

sudo mv jdk-7u15-linux-x64.tar.gz /usr/local/development

sudo tar -zxvf jdk-7u15-linux-x64.tar.gz

 4.修改环境变量

sudo gedit /etc/environment

 源文件的内容是这样的:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

 修改为:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:${JAVA_HOME}/bin"

JAVA_HOME=/usr/local/development/jdk1.7.0_15

JRE_HOME=${JAVA_HOME}/jre

CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/jre/lib"

 5.重新加载bashrc

source ~/.bashrc

 6.配置默认JDK

sudo update-alternatives --install /usr/bin/java java /usr/local/development/jdk1.7.0_15/bin/java 300

sudo update-alternatives --install /usr/bin/javac javac /usr/local/development/jdk1.7.0_15/bin/javac 300

sudo update-alternatives --install /usr/bin/jar jar /usr/local/development/jdk1.7.0_15/bin/jar 300

sudo update-alternatives --install /usr/bin/javap javap /usr/local/development/jdk1.7.0_15/bin/javap 300

sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/local/development/jdk1.7.0_15/bin/javadoc 300

7.设置默认JDK

sudo update-alternatives --config java

sudo update-alternatives --config javac

 8.测试:

java -version

 如下显示表示配置成功:

arlen@Arlen-TOP2:~$ java -version

java version "1.7.0_15"

Java(TM) SE Runtime Environment (build 1.7.0_15-b03)

Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

arlen@Arlen-TOP2:~$

 P.S:卸载OpenJDK(CentOS)

[arlen@Arlen-CentOS ~]$ rpm -qa | grep java

tzdata-java-2012j-1.el6.noarch

java-1.6.0-openjdk-1.6.0.0-1.50.1.11.5.el6_3.x86_64

java-1.7.0-openjdk-1.7.0.9-2.3.4.1.el6_3.x86_64

[arlen@Arlen-CentOS ~]$ su

密码:

[root@Arlen-CentOS arlen]# sudo rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.50.1.11.5.el6_3.x86_64

[root@Arlen-CentOS arlen]# sudo rpm -e --nodeps java-1.7.0-openjdk-1.7.0.9-2.3.4.1.el6_3.x86_64

[root@Arlen-CentOS arlen]# java

bash: java: command not found

[root@Arlen-CentOS arlen]# 

 

你可能感兴趣的:(ubuntu)