CentOS 7安裝jdk8

一、前期準備

環境:最小安裝的CentOS 7(虛擬機安裝的新版的centos系統,與6有一些配置文件上的差異),提前裝好了lrssz工具(不會安裝的,可以參看我的另一篇隨筆——lrssz的安裝)。

a) 首先從官網上下載Jdk 8 for Linux x64到window下。

b) 我這邊用的最小安裝,所以沒有安裝centos自帶的openjdk,如果你安裝時,不是最小安裝的話,可能集成了系統的openjdk,所以我們先要刪除自帶的openjdk,具體步驟如下:

1) 在系統終端輸入:rpm -qa | grep java,如果有openjdk的話,會出現類似於XXXX_openjdk_XXX的信息

2) 刪除openjdk,在終端輸入:rpm -e –-nodeps XXXX_openjdk_XXX 。即可刪除自帶的openjdk。

注意:上面這兩步可以一次性完成,而且很簡單哦!

rpm -e --nodeps `rpm -qa | grep java`

二、Jdk的安裝

a) 我們登錄超級用戶,在超級用戶目錄root下建立一個目錄app:

su root  #然後輸入密碼

mkdir app

b) 我們進入app,將下載好的jdk壓縮包導入centos:

cd app

rz #使用rz命令將jdk壓縮包從window導入centos當下目錄app中

c) 解壓jdk壓縮包

tar –zxvf jdk-8u45-linux-x64.gz

d) 解壓後的jdk的文件夾名字爲jdk1.8.0_45,我們把它改爲jdk1.8:

mv jdk1.8.0_45/ jdk1.8/

e) 進入jdk文件夾,獲取目錄絕對路徑(我的絕對路徑是:/root/app/jdk1.8):

cd jdk1.8

pwd

三、jdk的配置

a) 使用vim命令打開系統的環境變量配置文件:

vi /etc/profile

b) 在profile文件最後加入:

JAVA

export JAVA_HOME=/root/app/jdk1.8     #jdk的絕對路徑(我的是:/root/app/jdk1.8)
CLASSPATH=$JAVA_HOME/lib/
PATH=$PATH:$JAVA_HOME/bin
export PATH JAVA_HOME CLASSPATH

c)重啓機器 sudo shutdown -r now 或執行命令 source /etc/profile
四、配置驗證

a) 首先,我們輸入java –version,會得到:

java version "1.8.0_45"

Java(TM) SE Runtime Environment (build 1.8.0_45-b14)

Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

出現權限問題,則執行添加權限的命令:如

[root@iZcdqgn6qpldn9Z www]# java -version
-bash: /root/app/jdk1.8/bin/java: Permission denied

添加權限命令
chmod 775 /root/app/jdk1.8/bin/java

b) 我們再輸入javac,會得出:

Usage: javac <options> <source files>

where possible options include:

 -g                         Generate all debugging info

 -g:none                    Generate no debugging info     

 -g:{lines,vars,source}     Generate only some debugging info

-nowarn                    Generate no warnings

  -verbose                   Output messages about what the compiler is doing

  -deprecation               Output source locations where deprecated APIs are used

  -classpath <path>          Specify where to find user class files and annotation processors

-cp <path>                 Specify where to find user class files and annotation processors

-sourcepath <path>         Specify where to find input source files

-bootclasspath <path>      Override location of bootstrap class files

-extdirs <dirs>            Override location of installed extensions

-endorseddirs <dirs>       Override location of endorsed standards path

-proc:{none,only}          Control whether annotation processing and/or compilation is done.

-processor <class1>[,<class2>,<class3>...] Names of the annotation processors to run; bypasses default discovery process

-processorpath <path>      Specify where to find annotation processors

-parameters                Generate metadata for reflection on method parameters

-d <directory>             Specify where to place generated class files

-s <directory>             Specify where to place generated source files

-h <directory>             Specify where to place generated native header files

-implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files

-encoding <encoding>       Specify character encoding used by source files

-source <release>          Provide source compatibility with specified release

-target <release>          Generate class files for specific VM version

-profile <profile>         Check that API used is available in the specified profile

-version                   Version information

-help                      Print a synopsis of standard options

-Akey[=value]              Options to pass to annotation processors

-X                         Print a synopsis of nonstandard options

-J<flag>                   Pass <flag> directly to the runtime system

-Werror                    Terminate compilation if warnings occur

@<filename>                Read options and filenames from file

c) 如果得到以上兩步正確結果的話,恭喜你,你的jdk8就已經配置好了。

發佈了4 篇原創文章 · 獲贊 17 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章