debian手動安裝java兩種方法

方法一:下載後修改~/.bashrc文件java

方法二:使用update-alternatives進行命令安裝vim

相關配置記錄bash

法一:oracle

官網下載壓縮包,解壓,而後複製到/usr/lib/jvm目錄下,由於個人的debian系統有openjdk存放到這個目錄,因此我想統一目錄存放jvm

本地環境配置

vim ~/.bashrc 

#JAVA 
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_191
export JRE_HOME=$JAVA_HOME/jre
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib(<--注意這個‘.’很重要,表示當前目錄)


退出後: source ~/.bashrc

法二:.net

一樣下載壓縮包解壓到本身存放的目錄code

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_191/bin/java 200
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_191/bin/javac 200
## 後面的數字按照需求調整,貌似是優先級
## 第二句貌似不是必須,是jdk環境才須要配置的

而後設置默認jdkblog

update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      auto mode
  1            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  2            /usr/lib/jvm/jdk1.8.0_191/bin/java               200       manual mode
  3            /usr/lib/jvm/jdk1.8.0_191/bin/javac              200       manual mode

Press enter to keep the current choice[*], or type selection number: 2

選擇數字2rem

javac同理,再也不講述get

同時演示一下update-alternatives的使用

一、刪除存在的JDK
$ sudo update-alternatives --remove java /usr/lib/jvm/jdk1.8.0_191/bin/java
$ sudo update-alternatives --remove javac /usr/lib/jvm/jdk1.8.0_191/bin/javac

二、安裝新的JDK
$ sudo update-alternatives --install /usr/bin/java java /usr/lib/xxx/jdk1.x.0_xxx/bin/java 200
$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/xxx/jdk1.x.0_xxx/bin/javac 200

三、更新默認的JDK
$ update-alternatives --config java 
$ update-alternatives --config javac

四、刪除舊JDK目錄
$ sudo rm -rf /usr/lib/jvm/jdk1.8.0_191/

Reference:

https://blog.csdn.net/kongfu_cat/article/details/79510885

https://www.mkyong.com/java/how-to-install-oracle-jdk-8-on-debian/

相關文章
相關標籤/搜索