1. 程式人生 > >CentOS 7系統中JDK的安裝與配置

CentOS 7系統中JDK的安裝與配置

作業系統版本:CentOS Linux release 7.2.1511 (Core)

JDK版本:jdk-8u111-nb-8_2-linux-x64.sh

安裝方式:Shell指令碼安裝

下載地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html

安裝準備:

(1)檢視系統已安裝JDK版本(已安裝JDK版本為OpenJDK):

[[email protected] ~]# java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)

(2)檢視已安裝JDK詳細資訊:

[[email protected] ~]# rpm -qa | grep java
java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64
tzdata-java-2015g-1.el7.noarch
python-javapackages-3.4.1-11.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64

(3)解除安裝已安裝的OpenJDK:

[[email protected] ~]# rpm -e --nodeps tzdata-java-2015g-1.el7.noarch
[[email protected] ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.91-2.6.2.3.el7.x86_64
[[email protected] ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.91-2.6.2.3.el7.x86_64
[[email protected]

~]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.65-3.b17.el7.x86_64
[[email protected] ~]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.65-3.b17.el7.x86_64

安裝步驟:

(1)在Windows系統中從上述網站下載最新版JDK 64位版本。

(2)用WinSCP工具將下載的JDK檔案傳入虛擬機器中CentOS系統的/usr/local資料夾下。


(3)進入/usr/local資料夾,檢視jdk-8u111-nb-8_2-linux-x64.sh指令碼的執行許可權:

[[email protected] ~]# cd /usr/local
[[email protected] local]# ls
bin  games    jdk-8u111-nb-8_2-linux-x64.sh  lib64    sbin   src
etc  include  lib                            libexec  share
[[email protected] local]# ls -l
total 289396
drwxr-xr-x. 2 root root      4096 Aug 12  2015 bin
drwxr-xr-x. 2 root root      4096 Aug 12  2015 etc
drwxr-xr-x. 2 root root      4096 Aug 12  2015 games
drwxr-xr-x. 2 root root      4096 Aug 12  2015 include
-rw-r--r--. 1 root root 296300544 Nov  7 16:29 jdk-8u111-nb-8_2-linux-x64.sh
drwxr-xr-x. 2 root root      4096 Aug 12  2015 lib
drwxr-xr-x. 2 root root      4096 Aug 12  2015 lib64
drwxr-xr-x. 2 root root      4096 Aug 12  2015 libexec
drwxr-xr-x. 2 root root      4096 Aug 12  2015 sbin
drwxr-xr-x. 5 root root      4096 Nov  6 14:01 share
drwxr-xr-x. 2 root root      4096 Aug 12  2015 src

(4)增加root使用者對 jdk-8u111-nb-8_2-linux-x64.sh檔案的執行許可權:

[[email protected] local]# chmod u+x jdk-8u111-nb-8_2-linux-x64.sh 
[[email protected] local]# ls -l
total 289396
drwxr-xr-x. 2 root root      4096 Aug 12  2015 bin
drwxr-xr-x. 2 root root      4096 Aug 12  2015 etc
drwxr-xr-x. 2 root root      4096 Aug 12  2015 games
drwxr-xr-x. 2 root root      4096 Aug 12  2015 include
-rwxr--r--. 1 root root 296300544 Nov  7 16:29 jdk-8u111-nb-8_2-linux-x64.sh
drwxr-xr-x. 2 root root      4096 Aug 12  2015 lib
drwxr-xr-x. 2 root root      4096 Aug 12  2015 lib64
drwxr-xr-x. 2 root root      4096 Aug 12  2015 libexec
drwxr-xr-x. 2 root root      4096 Aug 12  2015 sbin
drwxr-xr-x. 5 root root      4096 Nov  6 14:01 share
drwxr-xr-x. 2 root root      4096 Aug 12  2015 src

(5)執行該JDK shell指令碼:

[[email protected] local]# ./jdk-8u111-nb-8_2-linux-x64.sh 
Configuring the installer...
Searching for JVM on the system...
Preparing bundled JVM ...
Extracting installation data...
Running the installer wizard...

(6)啟動了安裝嚮導:








(7)配置系統變數。在/etc/profile檔案末尾加入以下系統變數:

JAVA_HOME=/usr/local/jdk1.8.0_111
JRE_HOME=/usr/local/jdk1.8.0_111/jre
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JRE_HOME PATH CLASSPATH

(8)使檔案/etc/profile中的系統變數生效(本次只是臨時生效,下次系統啟動自動載入系統變數,才會永久生效):

[[email protected] ~]# source /etc/profile

(9)驗證配置是否正確:

[[email protected] ~]# echo $PATH
/usr/local/jdk1.8.0_111/bin:/usr/local/jdk1.8.0_111/jre/bin:/usr/lib64/qt3.3/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/root/bin
[[email protected] ~]# java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)