【转】http://blog.csdn.net/lipengshuai0507/article/details/17020131
1.首先下载最新版 jdk 64-bit版 (jdk-7u45-linux-x64.tar.gz)
从官网下载http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
2.将jdk-7u45-linux-x64.tar.gz拷贝到/usr/lib/jvm/目录下面,这里如果没有jdk文件夹,则创建该文件夹,命令:
sudo mkdir jvm //创建文件夹jdk
sudo cp -r ~/download/jdk-7u45-linux-x64.tar.gz /usr/lib/jvm/ //把下载的文件拷贝到新创建的目录下面
sudo tar -zxvg jdk-7u45-linux-x64.tar.gz //解压缩文件
3.设置环境变量,用nano打开/etc/profile文件
sudo nano /etc/profile
在文件的最后面增加:
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_45
export JRE_HOME=/usr/lib/jvm/jdk1.7.0_45/jre
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_45/bin/java 300
$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_45/bin/javac 300
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac
5.检测,输入java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)