Linux-JDK安装

1、下载

去oracle官网下载jdk https://www.oracle.com/technetwork/cn/java/javase/downloads/jdk8-downloads-2133151-zhs.html

我使用的是 jdk-8u201-linux-x64.tar.gz

2、解压

我解压到了/opt/software目录

[root@localhost package]# tar -zxvf jdk-8u201-linux-x64.tar.gz -C /opt/software/

3、配环境变量

/etc/profile文件的改变会涉及到系统的环境,我们要将jdk配置到/etc/profile,才可以在任何一个目录访问jdk

编辑文件

[root@localhost jdk1.8.0_201]# vim /etc/profile

按Shift+G到文件末尾,按o向下一行编辑,粘贴下面内容。

export JAVA_HOME=/opt/software/jdk1.8.0_201  #jdk安装目录
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}

wq保存退出。

编辑后生效

[root@localhost jdk1.8.0_201]# source /etc/profile

4、检测

输入javac 或者 java -version

[root@localhost jdk1.8.0_201]# javac
Usage: javac  
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           Specify where to find user class files and annotation processors
  -cp                  Specify where to find user class files and annotation processors
  -sourcepath          Specify where to find input source files
  -bootclasspath       Override location of bootstrap class files
  -extdirs             Override location of installed extensions
  -endorseddirs        Override location of endorsed standards path
  -proc:{none,only}          Control whether annotation processing and/or compilation is done.
  -processor [,,...] Names of the annotation processors to run; bypasses default discovery process
  -processorpath       Specify where to find annotation processors
  -parameters                Generate metadata for reflection on method parameters
  -d              Specify where to place generated class files
  -s              Specify where to place generated source files
  -h              Specify where to place generated native header files
  -implicit:{none,class}     Specify whether or not to generate class files for implicitly referenced files
  -encoding        Specify character encoding used by source files
  -source           Provide source compatibility with specified release
  -target           Generate class files for specific VM version
  -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                   Pass  directly to the runtime system
  -Werror                    Terminate compilation if warnings occur
  @                Read options and filenames from file
[root@localhost jdk1.8.0_201]# java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

你可能感兴趣的:(Linux-JDK安装)