1,首先到Oracle上下载jdk-7u5-linux-x64.tar.gz:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1637583.html
2,将jdk-7u5-linux-x64.tar.gz拷贝到/usr/lib/jvm/目录接下来,
命令:
sudo cp -r ~/下载/jdk-7u5-linux-x64.tar.gz
这里一旦没有jvm文件夹,则创建该文件夹,命令:
sudo mkdir jvm
进入/usr/lib/jvm目录
cd /usr/lib/jvm
将文件解压到接下来,命令:
sudo tar -zxvf jdk-7u5-linux-x64.tar.gz
3,设置环境变量,用gedit打开/etc/profile文件
sudo gedit /etc/profile
在文件的最后面增加:
export JAVA_HOME=/usr/lib/jdk1.7.0_05
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$CLASSPATH:.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
4,将系统默认的jdk修改过来
$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_05/bin/java 300
$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_05/bin/javac 300
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac
5,检测,输入命令行:
java -version
显示如下结果,便是配置完成
java version "1.7.0_05"
Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)