一、yum安装
1.1 查看yum的java版本
[root@rancher ~]# yum -y list java* |grep 1.8
java-1.8.0-openjdk.i686 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk.x86_64 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk-accessibility.i686 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk-demo.i686 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk-devel.i686 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk-headless.i686 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk-src.i686 1:1.8.0.332.b09-1.el7_9 updates
java-1.8.0-openjdk-src.x86_64 1:1.8.0.332.b09-1.el7_9 updates
1.2 命令安装
shell>yum install java-1.8.0-openjdk.x86_64
1.3 查看Java版本
shell>java -version
二、官网源码安装
2.1 官网下载jdk
进入 Oracle 官方网站 下载合适的 JDK 版本,准备安装。
把文件放到/tmp目录下
2.2 创建目录并解压
[root@rancher tmp]# mkdir -p /data/app
[root@rancher tmp]# tar -zxvf jdk-8u333-linux-x64.tar.gz -C /data/app
[root@rancher tmp]# cd /data/app/
[root@rancher app]# mv jdk1.8.0_333 jdk
2.3 设置环境变量
[root@rancher jdk]# vim /etc/profile
# JAVA_HOME是自己的jdk解压目录
export JAVA_HOME=/data/app/jdk
export PATH=$PATH:$JAVA_HOME/bin
[root@rancher jdk]source /etc/profile
2.4 查看JAVA版本
[root@rancher jdk]# java -version
java version "1.8.0_333"
Java(TM) SE Runtime Environment (build 1.8.0_333-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.333-b02, mixed mode)