centos 7安裝部署java jdk 8,設定java環境變數(超詳細,其他linux系統也可通過該方法安裝java,配置java環境變數)
前置配置
作業系統:CentOS Linux release 7.5.1804
Java版本號:jdk1.8.0_191
#OS版本號查詢
[[email protected] ~]$ cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core)
java jdk 下載
jdk 8下載地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
選擇:jdk-8u191-linux-x64.tar.gz
下載到本地目錄:/home/troll/Downloads
解壓jdk
假設安裝目錄為/home/troll/softs/
[[email protected]
jdk1.8.0_191
檢視是否系統自帶jdk
[[email protected] Downloads]$ #檢視系統是否已經安裝jdk
[[email protected] Downloads]$ rpm -qa | grep java
java
-1.7.0-openjdk-headless-1.7.0.191-2.6.15.4.el7_5.x86_64
tzdata-java
-2018e-3.el7.noarch
java
-1.8.0-openjdk-headless-1.8.0.181-3.b13.el7_5.x86_64
java
-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64 #
java
packages-tools-3.4.1-11.el7.noarch
java
-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64
解除安裝系統自帶jdk
sudo rpm -e java-1.7.0-openjdk sudo rpm -e icedtea-web #依賴 sudo rpm -e rhino #依賴 sudo rpm -e jline #依賴 sudo rpm -e java-1.8.0-openjdk-headless sudo rpm -e java-1.8.0-openjdk
#檢查系統自帶jdk是否解除安裝完成 [[email protected] Downloads]$ rpm -qa | grep java [[email protected] Downloads]$
#配置jdk環境變數
注意:
全域性java環境變數設定/etc/profile
當前使用者java環境變數設定~/.bash_profile
[[email protected] jdk1.8.0_191]KaTeX parse error: Expected 'EOF', got '#' at position 21: …/etc/profile``
#̲使用者java環境變數設定
[t… vi ~/.bash_profile
#java env
JAVA_HOME=/home/troll/softs/jdk1.8.0_191
CLASSPATH=$JAVA_HOME/lib
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
#引用環境變數
source ~/.bash_profile
#測試安裝是否成功
[[email protected] jdk1.8.0_191]$ java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
部署成功