linux安装openjdk,jdk的快速安装

快速安装

检索

yum search java|grep jdk

得出结果如下:

Repository epel is listed more than once in the configuration
Last metadata expiration check: 1:23:37 ago on Tue 20 Apr 2021 08:21:35 AM CST.
java-1.8.0-openjdk.x86_64 : OpenJDK 8 Runtime Environment
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK 8 accessibility connector
java-1.8.0-openjdk-demo.x86_64 : OpenJDK 8 Demos
java-1.8.0-openjdk-devel.x86_64 : OpenJDK 8 Development Environment
java-1.8.0-openjdk-headless.x86_64 : OpenJDK 8 Headless Runtime Environment
java-1.8.0-openjdk-javadoc.noarch : OpenJDK 8 API documentation
java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK 8 API documentation compressed in a single archive
java-1.8.0-openjdk-src.x86_64 : OpenJDK 8 Source Bundle
java-11-openjdk.x86_64 : OpenJDK Runtime Environment 11
java-11-openjdk-demo.x86_64 : OpenJDK Demos 11
java-11-openjdk-devel.x86_64 : OpenJDK Development Environment 11
java-11-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 11
java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation
java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in a single archive
java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11
java-11-openjdk-src.x86_64 : OpenJDK Source Bundle 11
java-11-openjdk-static-libs.x86_64 : OpenJDK libraries for static linking 11
java-latest-openjdk.x86_64 : OpenJDK 16 Runtime Environment
java-latest-openjdk-demo.x86_64 : OpenJDK 16 Demos
java-latest-openjdk-demo-fastdebug.x86_64 : OpenJDK 16 Demos with minimal debugging on
java-latest-openjdk-demo-slowdebug.x86_64 : OpenJDK 16 Demos with full debugging on
java-latest-openjdk-devel.x86_64 : OpenJDK 16 Development Environment
java-latest-openjdk-devel-fastdebug.x86_64 : OpenJDK 16 Development Environment with minimal debugging on
java-latest-openjdk-devel-slowdebug.x86_64 : OpenJDK 16 Development Environment with full debugging on
java-latest-openjdk-fastdebug.x86_64 : OpenJDK 16 Runtime Environment with minimal debugging on
java-latest-openjdk-headless.x86_64 : OpenJDK 16 Headless Runtime Environment
java-latest-openjdk-headless-fastdebug.x86_64 : OpenJDK 16 Runtime Environment with minimal debugging on
java-latest-openjdk-headless-slowdebug.x86_64 : OpenJDK 16 Runtime Environment with full debugging on
java-latest-openjdk-javadoc.x86_64 : OpenJDK 16 API documentation
java-latest-openjdk-javadoc-zip.x86_64 : OpenJDK 16 API documentation compressed in a single archive
java-latest-openjdk-jmods.x86_64 : JMods for OpenJDK 16
java-latest-openjdk-jmods-fastdebug.x86_64 : JMods for OpenJDK 16 with minimal debugging on
java-latest-openjdk-jmods-slowdebug.x86_64 : JMods for OpenJDK 16 with full debugging on
java-latest-openjdk-slowdebug.x86_64 : OpenJDK 16 Runtime Environment with full debugging on
java-latest-openjdk-src.x86_64 : OpenJDK 16 Source Bundle
java-latest-openjdk-src-fastdebug.x86_64 : OpenJDK 16 Source Bundle %{for_fastdebug}
java-latest-openjdk-src-slowdebug.x86_64 : OpenJDK 16 Source Bundle for packages with debugging on
java-latest-openjdk-static-libs.x86_64 : OpenJDK 16 libraries for static linking
java-latest-openjdk-static-libs-fastdebug.x86_64 : OpenJDK 16 libraries for static linking with minimal debugging on
java-latest-openjdk-static-libs-slowdebug.x86_64 : OpenJDK 16 libraries for static linking with full debugging on

安装

yum install java-1.8.0-openjdk

输入 Y

路径

/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-2.el8_3.x86_64/

版本号在不同时间不同,可以根据此目录结构自行寻找

检查

java -version

返回结果

openjdk version "1.8.0_282"
OpenJDK Runtime Environment (build 1.8.0_282-b08)
OpenJDK 64-Bit Server VM (build 25.282-b08, mixed mode)

注意

以上安装的只是JRE,只有jre目录

安装开发环境

yum install java-1.8.0-openjdk-devel.x86_64

输入 Y

输入javac验证

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

设置环境变量

编辑profile文件

vi /etc/profile

如果只对某用户生效

vi ~/bash_profile

在结尾输入内容

JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.282.b08-2.el8_3.x86_64
JRE_HOME=$JAVA_HOME/jre
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH

使环境生效

执行source命令

source /etc/profile

或者

source ~/.bash_profile

查看环境变量

echo $JAVA_HOME