centos安裝jdk8

KeepSmiling_me發表於2024-03-28

1. 檢查系統中的jdk版本

java -version
複製程式碼

顯示:

openjdk version "1.8.0_102"
OpenJDK Runtime Environment (build 1.8.0_102-b14)
OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)
複製程式碼

2. 查詢自帶的openjdk

rpm -qa | grep -i java
複製程式碼

顯示:

java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
複製程式碼

3. 解除安裝openjdk

rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
複製程式碼

或者使用

yum remove *openjdk*
複製程式碼

之後再次輸入rpm -qa | grep java 檢視解除安裝情況

4. 檢查系統環境

//i686表示32位  x86_64表示是64位
[root@node3 kafka_2.12-1.1.0]# uname -a
Linux localhost 3.10.0-862.2.3.el7.x86_64 #1 SMP Wed May 9 18:05:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
複製程式碼

5. 下載

根據作業系統位數,在官網下載相應的tar.gz包。

centos安裝jdk8
解壓

mkdir -p /usr/local/java 
tar zxvf ../software/jdk-8u77-linux-x64.tar.gz -C /usr/local/java
複製程式碼

6. 配置環境變數

vi /etc/profile
複製程式碼

注:如果修改當前使用者的環境變數 編輯~/.profile或~/.bashrc檔案即可,而不是/etc/profile。

在檔案最後新增如下配置:

JAVA_HOME=/usr/local/java/jdk1.8.0_161 
export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/ 
export PATH=$PATH:$JAVA_HOME/bin 
複製程式碼

重新載入配置檔案,使配置生效(su root):

source /etc/profile
複製程式碼

source ~/.bash_profile
複製程式碼

7. 檢查是否安裝成功

檢視java安裝指令碼

java -version
複製程式碼

顯示:

java version “1.8.0_161” 
Java(TM) SE Runtime Environment (build 1.8.0_161-b12) 
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
複製程式碼

檢視執行引數

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
複製程式碼

出現以上資訊則代表安裝成功。

相關文章