Linux 环境 使用yum 安装 openjdk1.8

Linux 环境 使用yum 安装 openjdk1.8

在实际生产环境中要尽量使用OpenJDK开源环境。谨防在误使用正式版Java环境,而导致律师函在路上的情况

1. 查找Yum源查找JDK

yum search java | grep jdk
运行结果:

[root@VM-8-4-centos .ssh]# yum search java | grep jdk
Repository epel is listed more than once in the configuration
ldapjdk-javadoc.noarch : Javadoc for ldapjdk
java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment 8
java-1.8.0-openjdk.x86_64 : OpenJDK 8 Runtime Environment
java-1.8.0-openjdk-accessibility.i686 : OpenJDK accessibility connector
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.8.0-openjdk-demo.i686 : OpenJDK Demos 8
java-1.8.0-openjdk-demo.x86_64 : OpenJDK 8 Demos
java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment 8
java-1.8.0-openjdk-devel.x86_64 : OpenJDK 8 Development Environment
java-1.8.0-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 8
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
java-1.8.0-openjdk-src.i686 : OpenJDK Source Bundle 8
java-1.8.0-openjdk-src.x86_64 : OpenJDK 8 Source Bundle
java-11-openjdk.i686 : OpenJDK Runtime Environment 11
java-11-openjdk.x86_64 : OpenJDK 11 Runtime Environment
java-11-openjdk-demo.i686 : OpenJDK Demos 11
java-11-openjdk-demo.x86_64 : OpenJDK 11 Demos
java-11-openjdk-devel.i686 : OpenJDK Development Environment 11
java-11-openjdk-devel.x86_64 : OpenJDK 11 Development Environment
java-11-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 11
java-11-openjdk-headless.x86_64 : OpenJDK 11 Headless Runtime Environment
java-11-openjdk-javadoc.i686 : OpenJDK 11 API documentation
java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation
java-11-openjdk-javadoc-zip.i686 : OpenJDK 11 API documentation compressed in a
java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in
java-11-openjdk-jmods.i686 : JMods for OpenJDK 11
java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11
java-11-openjdk-src.i686 : OpenJDK Source Bundle 11
java-11-openjdk-src.x86_64 : OpenJDK 11 Source Bundle
java-11-openjdk-static-libs.i686 : OpenJDK libraries for static linking 11
java-11-openjdk-static-libs.x86_64 : OpenJDK 11 libraries for static linking
java-latest-openjdk.x86_64 : OpenJDK 16 Runtime Environment
java-latest-openjdk-debug.x86_64 : OpenJDK 16 Runtime Environment with full
java-latest-openjdk-demo.x86_64 : OpenJDK 16 Demos
java-latest-openjdk-demo-debug.x86_64 : OpenJDK 16 Demos with full debugging on
java-latest-openjdk-demo-fastdebug.x86_64 : OpenJDK 16 Demos with minimal
java-latest-openjdk-devel.x86_64 : OpenJDK 16 Development Environment
java-latest-openjdk-devel-debug.x86_64 : OpenJDK 16 Development Environment with
java-latest-openjdk-devel-fastdebug.x86_64 : OpenJDK 16 Development Environment
java-latest-openjdk-fastdebug.x86_64 : OpenJDK 16 Runtime Environment with
java-latest-openjdk-headless.x86_64 : OpenJDK 16 Headless Runtime Environment
java-latest-openjdk-headless-debug.x86_64 : OpenJDK 16 Runtime Environment with
java-latest-openjdk-headless-fastdebug.x86_64 : OpenJDK 16 Runtime Environment
java-latest-openjdk-javadoc.x86_64 : OpenJDK 16 API documentation
java-latest-openjdk-javadoc-zip.x86_64 : OpenJDK 16 API documentation compressed
java-latest-openjdk-jmods.x86_64 : JMods for OpenJDK 16
java-latest-openjdk-jmods-debug.x86_64 : JMods for OpenJDK 16 with full
java-latest-openjdk-jmods-fastdebug.x86_64 : JMods for OpenJDK 16 with minimal
java-latest-openjdk-src.x86_64 : OpenJDK 16 Source Bundle
java-latest-openjdk-src-debug.x86_64 : OpenJDK 16 Source Bundle for packages
java-latest-openjdk-src-fastdebug.x86_64 : OpenJDK 16 Source Bundle
java-latest-openjdk-static-libs.x86_64 : OpenJDK 16 libraries for static linking
java-latest-openjdk-static-libs-debug.x86_64 : OpenJDK 16 libraries for static
java-latest-openjdk-static-libs-fastdebug.x86_64 : OpenJDK 16 libraries for
ldapjdk.noarch : The Mozilla LDAP Java SDK

2. 执行安装命令

yum install java-1.8.0-openjdk -y

安装成功后,默认安装路径在/usr/lib/jvm/下边,
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el6_9.x86_64

查看安装路径(如下所示):

which java
ls -lrt /usr/bin/java

验证Java是否安装成功

java -version
运行结果:

[root@VM-8-4-centos .ssh]# java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)

3. 如果需要开发环境 则安装JDK环境

yum install java-1.8.0-openjdk-devel.x86_64 -y

验证JDK是否安装成功

javac -version
运行结果:

[root@VM-8-4-centos .ssh]# javac -version
javac 1.8.0_292

4. 配置环境变量

  1. 先进入 /usr/lib/jvm 查看jdk安装目录
cd /usr/lib/jvm 
ls
  1. 找到目录 java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64
    版本可能存在 差异所以目录可能会有所不同

  2. 修改/etc/profile文件

vi + /etc/profile

profile文件底部 增加

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64
export JRE_HOME=$JAVA_HOME/jre
export CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

使环境变量生效

source /etc/profile

本文由 在码圈 创作,如果您觉得本文不错,请随意赞赏
采用 知识共享署名4.0 国际许可协议进行许可
您可以自由的转载和修改,但请务必注明文章来源并且不可用于商业目的。
本站部分内容收集于互联网,如果有侵权内容、不妥之处,请联系我们删除。敬请谅解!
原文链接:https://bedebug.com/archives/openjdk
最后更新于:2021-05-12 15:17:42

请博主喝咖啡 ☕.