Linux下安裝JDK 1.8

前言

JDK是 JAVA 的軟件開發工具包,若是要使用JAVA來進行開發,或者部署基於其開發的應用,那麼就須要安裝JDK。本次將在Linux下安裝JDK及配置環境。html

本人環境:CentOS 7.3 64位java

下載JDK

在安裝以前,檢查是否存在Linux下自帶的OpenJDK,命令:rpm -qa | grep java。若存在,則須要進行卸載,命令:rpm -e --nodeps 卸載的軟件名node

JDK歷史版本連接:https://www.oracle.com/technetwork/java/javase/archive-139210.htmllinux

接着,咱們能夠經過 wget 命令下載JDK安裝包,或者下載後傳到Linux。我這裏下載的安裝包版本是 jdk-8u131-linux-x64.tar.gzbootstrap

解壓安裝包

建立一個文件夾,用於存放JDK安裝包,而後解壓到該目錄下。vim

建立文件夾:mkdir /root/JDK
進入文件夾:cd /root/JDK
解壓:tar -zxvf /root/JDK/jdk-8u131-linux-x64.tar.gzbash

解壓

能夠看到,本次解壓到了當前目錄 /root/JDK/jdk1.8.0_131下。oracle

配置環境

解壓完成以後,咱們要配置下環境變量,經過 vim 命令修改配置文件 /etc/profile 來設置環境變量。ide

vim /etc/profile工具

在文件最後一行,輸入 i 進入編輯模式,添加如下內容,而後按 Esc 退出編輯模式,再輸入 :wq 保存並退出。

export JAVA_HOME=/root/JDK/jdk1.8.0_131  
export JRE_HOME=${JAVA_HOME}/jre  
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib  
export  PATH=${JAVA_HOME}/bin:$PATH

設置完以後,若是要使環境變量當即生效,須要經過命令:source /etc/profile,從新加載配置文件。

驗證是否安裝成功

全部都配置好了,咱們須要驗證下是否安裝成功。

依次輸入 java -versionjavajavac,不會出現報錯而且顯示出 jdk版本號java/javac相關命令參數說明界面

[root@wintest JDK]# java -version
-bash: java: command not found
[root@wintest JDK]# source /etc/profile
[root@wintest JDK]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
[root@wintest JDK]# java
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32          use a 32-bit data model if available
    -d64          use a 64-bit data model if available
    -server       to select the "server" VM
                  The default VM is server.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose:[class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  Warning: this feature is deprecated and will be removed
                  in a future release.
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  Warning: this feature is deprecated and will be removed
                  in a future release.
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                  see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument
    -splash:<imagepath>
                  show splash screen with specified image
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for more details.
[root@wintest JDK]# 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
[root@wintest JDK]#
相關文章
相關標籤/搜索