1、去官网下载JDK
2、root权限并解压,复制到/usr/lib/jvm
sudo su
tar -zxvf jdk-7u21-linux-i586.tar.gz mv jdk1.7.0_21/ /usr/lib/jvm
3、配置环境变量gedit ~/.bashrc
在末尾添加
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_21 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
立即生效:source ~/.bashrc
4、配置默认JDKsudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_21/bin/java 300 sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_21/bin/javac 300 sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.7.0_21/bin/jar 300
检查
sudo update-alternatives --config java
5、查看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)