1. 下载
Oracle网站下载JDK7
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
根据机器的操作系统选择适合的版本,这里我们选择 jdk-7u75-linux-x64.tar.gz
2. 安装
sudo mkdir /usr/lib/jvm
sudo tar zxvf ./jdk-7u75-linux-x64.tar.gz -C /usr/lib/jvmcd /usr/lib/jvm
sudo mv jdk-7u75-linux-x64/ java-7-sun
3. 配置环境变量
vi /etc/environment
添加:
export JAVA_HOME=/usr/lib/jvm/java-7-sun export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
使配置文件生效:source /etc/environment
4. 配置默认JDK
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-7-sun/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-7-sun/bin/javac 300
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/java-7-sun/bin/jar 300
sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/java-7-sun/bin/javah 300
sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/java-7-sun/bin/javap 300
执行 sudo update-alternatives --config java
5. 测试
java -version