1.下载JDK
https://www.oracle.com/java/technologies/javase-jdk8-downloads.html
Oracle官网下载慢的同学可以访问华为的镜像库
https://repo.huaweicloud.com/java/jdk/
2.配置JDK
解压jdk文件
tar -zxvf jdk-8u231-linux-x64.tar.gz
配置环境变量
vim /etc/profile
# Set java environment
JAVA_HOME=/usr/local/java/jdk1.8.0_231
JRE_HOME=/usr/local/java/jdk1.8.0_231/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
3.配置生效
source /etc/profile
4.查看结果
java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
如图所示,则安装成功。