查看本机是否自带java
#rpm -qa|grep java
有则卸载(选做)
#rpm -e --nodeps java*
查看yum中jdk版本
#yum search jdk
列出java11
#yum list |grep java-11
安装必要的(-y表示安装过程中都默认yes)
#yum install -y java-11-openjdk.x86_64
#yum install -y java-11-openjdk-devel.x86_64
#yum install -y java-11-openjdk-headless.x86_64
查看是否安装成功
#rpm -qa | grep jdk
copy-jdk-configs-3.3-10.el7_5.noarch
java-11-openjdk-headless-11.0.13.0.8-1.el7_9.x86_64
java-11-openjdk-11.0.13.0.8-1.el7_9.x86_64
java-11-openjdk-devel-11.0.13.0.8-1.el7_9.x86_64
默认的安装目录是在/usr/lib/jvm/ ,若没有可以查到yum安装jdk的位置(选做)
#rpm -ql jdk java-11-openjdk-11.0.13.0.8-1.el7_9.x86_64
/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-1.el7_9.x86_64
设置环境变量
#vi /etc/profile
加入以下配置
#set java environment
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.13.0.8-1.el7_9.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
保存退出:esc :wq 回车
让修改生效
#source /etc/profile
验证jdk配置
#java -version
openjdk version "11.0.13" 2021-10-19 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.13+8-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8-LTS, mixed mode, sharing)
#javac -version
javac 11.0.13
#cd $JAVA_HOME
[root@abcd java-11-openjdk-11.0.13.0.8-1.el7_9.x86_64]#