One, download JDK
Check the JDK version information that can be installed on the current centos
yum search java | grep -i --color JDK
Specify a corresponding version of JDK to download
sudo yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel
Enter y when you need to choose
Wait for the installation to complete
Two, configure environment variables
View the JDK installation directory
dirname $(readlink $(readlink $(which java)))
Visible: JDK installation directory is: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.272.b10-3.el8_3.x86_64/jre/bin
Edit bashrc
vim ~/.bashrc
Add the following single line at the end of the file
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk
Then click "esc" and enter ":wq" to save and exit.
Execute the following code to make the environment variable take effect
source ~/.bashrc
Check installation
echo $JAVA_HOME # 检验变量值
java -version #查看Java版本
$JAVA_HOME/bin/java -version #查看Java版本
The output result is consistent with the result of "java -version", which means the configuration is successful.