Install JDK and configure environment variables for centos-8.2.2004

One, download JDK

Check the JDK version information that can be installed on the current centos

yum search java | grep -i --color JDK

Insert picture description here

Specify a corresponding version of JDK to download

sudo yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel

Insert picture description here
Enter y when you need to choose

Wait for the installation to complete

Insert picture description here

Two, configure environment variables

View the JDK installation directory

dirname $(readlink $(readlink $(which java)))

Insert picture description here
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

Insert picture description here

Add the following single line at the end of the file

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk

Insert picture description here
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     # 检验变量值

Insert picture description here

java -version #查看Java版本

Insert picture description here

$JAVA_HOME/bin/java -version #查看Java版本

Insert picture description here
The output result is consistent with the result of "java -version", which means the configuration is successful.

Guess you like

Origin blog.csdn.net/qq_45154565/article/details/111456562
Recommended