ubuntu14安装jdk7:
官网下载:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
选择 accept license ,选择适合自己机型的JDK下载。
解压文件:
$ sudo mkdir /usr/lib/jvm
$ sudo tar -zxvf jdk-7u55-linux-i586.tar.gz -C /usr/lib/jvm
如果修改文件名(本文没有修改):
$ cd /usr/lib/jvm
$ sudo mv jdk1.7.0_55 java
添加环境变量:
$ sudo gedit ~/.bashrc
添加如下内容:
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_55
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
配置默认JDK版本:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_55/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_55/bin/javac 300
sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.7.0_55/bin/jar 300
sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk1.7.0_55/bin/javah 300
sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.7.0_55/bin/javap 300
配置选项:
执行 sudo update-alternatives --config java
若是初次安装 JDK, 将提示There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java/bin/java无需配置。
若是非初次安装,将有不同版本的 JDK 选项。
测试:
$ java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b113)
Java HotSpot(TM) Server VM (build 24.55-b03, mixed mode)