1. 下载 JDK
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup- cookie" https://download.oracle.com/otn/java/jdk/8u221-b11/230deb18db3e4014bb8e3e8324f81b43/jdk-8u221-linux-x64.tar.gz
提示错误: -bash: wget: command not found
yum -y install wget
2. 安装
-
创建安装目录
mkdir /usr/local/java/
-
解压至安装目录
tar -zxvf jdk-8u221-linux-x64.tar.gz -C /usr/local/java/
3. 设置环境变量
-
打开文件
> vim /etc/profile > 提示错误: -bash: vim: command not found > yum -y install vim* > :q 退出vim :q! 直接退出不保存 :wq 保存并退出 :wq! (在可以转换权限的情况下)强制保存并退出
-
在末尾添加
export JAVA_HOME=/usr/local/java/jdk1.8.0_221 export JRE_HOME=${JAVA_HOME}/jre export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
-
使环境变量生效
> source /etc/profile
# 4. 添加软链接
> ln -s /usr/local/java/jdk1.8.0_221/bin/java /usr/bin/java
# 5. 检查
> java -version > ![image](https://yqfile.alicdn.com/5945316b8083e9f9a630dc5e7cb11fb21cbc5b2b.png)