1:經過ppa(源) 方式安裝.html
2:經過官網下載安裝包安裝.java
這裏推薦第1種,由於能夠經過 apt-get upgrade 方式方便得到jdk的升級linux
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update
jdk7web
sudo apt-get install oracle-java7-installer
jdk8ubuntu
sudo apt-get install oracle-java8-installer
安裝器會提示你贊成 oracle 的服務條款,選擇 okvim
而後選擇yes 便可bash
若是你懶,不想本身手動點擊.也能夠加入下面的這條命令,默認贊成條款:oracle
JDK7 默認選擇條款jvm
echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
JDK8 默認選擇條款jsp
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
接下會是等待(依我的網速定)
若是你由於防火牆或者其餘緣由,致使installer 下載速度很慢,能夠中斷操做.而後下載好相應jdk的tar.gz 包,放在:
/var/cache/oracle-jdk7-installer (jdk7)
/var/cache/oracle-jdk8-installer (jdk8)
下面,而後安裝一次installer. installer 則會默認使用 你下載的tar.gz包
JDk7
sudo update-java-alternatives -s java-7-oracle
JDK8
sudo update-java-alternatives -s java-8-oracle
若是即安裝了jdk7,又安裝了jdk8,要實現二者的切換,能夠:
jdk8 切換到jdk7
sudo update-java-alternatives -s java-7-oracle
jdk7 切換到jdk8
sudo update-java-alternatives -s java-8-oracle
4.測試jdk 是是否安裝成功:
java -version javac -version
分爲下面5個步驟
1.官網下載JDK
2.解壓縮,放到指定目錄
3.配置環境變量
4.設置系統默認JDK
5. 測試jdk
地址: http://www.oracle.com/technetwork/articles/javase/index-jsp-138363.html
選擇相應的 .gz包下載
建立目錄:
sudo mkdir /usr/lib/jvm
加壓縮到該目錄:
sudo tar -zxvf jdk-7u60-linux-x64.gz -C /usr/lib/jvm
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
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
如果初次安裝jdk,會有下面的提示
There is only one alternative in link group java (providing /usr/bin/java):
/usr/lib/jvm/jdk1.7.0_60/bin/java
否者,選擇合適的jdk
java -version java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
jdk 安裝成功
參考文章:
1. http://www.webupd8.org/2012/01/install-oracle-java-jdk-7-in-ubuntu-via.html
2. http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html