Ubuntu 安装 JDK 7 / JDK8 的两种方式
ubuntu 安装jdk 的两种方式:
@H_403_5@1:通过ppa(源) 方式安装. @H_403_5@2:通过官网下载安装包安装. @H_403_5@这里推荐第1种,因为可以通过 apt-get upgrade 方式方便获得jdk的升级使用ppa/源方式安装
1.添加ppa
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update
2.安装oracle-java-installer
@H_403_5@ jdk7sudo apt-get install oracle-java7-installer
sudo apt-get install oracle-java8-installer
echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
3.设置系统默认jdk
@H_403_5@JDk7sudo update-java-alternatives -s java-7-oracle
sudo update-java-alternatives -s java-8-oracle
sudo update-java-alternatives -s java-7-oracle
sudo update-java-alternatives -s java-8-oracle
java -version
javac -version
直接下载jdk压缩包方式安装(这里只介绍jdk7的,jdk8 的原理完全一致)
@H_403_5@ 分为下面5个步骤 @H_403_5@ 1.官网下载JDK @H_403_5@ 2.解压缩,放到指定目录 @H_403_5@ 3.配置环境变量 @H_403_5@ 4.设置系统默认JDK @H_403_5@ 5. 测试jdk1.官网下载JDK
地址:http://www.oracle.com/technetwork/articles/javase/index-jsp-138363.html @H_403_5@ 选择相应的 .gz包下载2. 解压缩,放到指定目录(以jdk-7u60-linux-x64.gz为例)
@H_403_5@ 创建目录:sudo mkdir /usr/lib/jvm
sudo tar -zxvf jdk-7u60-linux-x64.gz -C /usr/lib/jvm
3.修改环境变量:
sudo vim ~/.bashrc
#set oracle jdk environment export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_60 ## 这里要注意目录要换成自己解压的jdk 目录 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
source ~/.bashrc
4.设置系统默认jdk 版本
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.7.0_60/bin/java 300 sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.7.0_60/bin/javac 300 sudo update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/jdk1.7.0_60/bin/jar 300 sudo update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/jdk1.7.0_60/bin/javah 300 sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk1.7.0_60/bin/javap 300
sudo update-alternatives --config java
@H_403_5@ There is only one alternative in link group java (providing /usr/bin/java):
/usr/lib/jvm/jdk1.7.0_60/bin/java
@H_403_5@ 否者,选择合适的jdk
/usr/lib/jvm/jdk1.7.0_60/bin/java
5.测试jdk
java -version java version "1.7.0_60"@H_403_5@ Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09,mixed mode)