Ubuntu18.04 安裝 JDK7

直接下載jdk壓縮包方式安裝

 

1.官網下載JDK   

     地址: http://www.oracle.com/technetwork/articles/javase/index-jsp-138363.html

  選擇相應的 .gz包下載 html

2. 解壓縮,放到指定目錄(以jdk-7u60-linux-x64.gz爲例)

  建立目錄:java

sudo mkdir /usr/lib/jvm

 加壓縮到該目錄:linux

 sudo tar -zxvf jdk-7u60-linux-x64.gz -C /usr/lib/jvm

3.修改環境變量:  

sudo vim ~/.bashrc

 文件的末尾追加下面內容:vim

#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

 使環境變量立刻生效bash

 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 
複製代碼

 而後執行:oracle

sudo update-alternatives --config java

    如果初次安裝jdk,會有下面的提示     jvm

   There is only one alternative in link group java (providing /usr/bin/java):
    /usr/lib/jvm/jdk1.7.0_60/bin/javajsp

 否者,選擇合適的jdk測試

5.測試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)
ui

複製代碼

  jdk 安裝成功

相關文章
相關標籤/搜索