具体步骤参详了如下链接:
1、到 Sun 的官网下载
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
选择 accept license ,然后选择适合自己机型的JDK下载。
2、解压文件,修改文件名
$ sudomkdir /usr/lib/jvm $ sudotar zxvf jdk-7u21-linux-i586.tar.gz -C /usr/lib/jvm $ cd /usr/lib/jvm $ sudo mv jdk1.7.0_21 java
3、添加环境变量
$ sudo vim ~/.bashrc
加入如下内容
export JAVA_HOME=/usr/lib/jvm/java export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
- sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java/bin/java 300
- sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java/bin/javac 300
执行代码:
- sudo update-alternatives --config java
$ java -version java version "1.7.0_21" Java(TM) SE Runtime Environment (build 1.7.0_21-b11) Java HotSpot(TM) Server VM (build 23.21-b01, mixed mode)