centos7安装Java

1、下载安装包
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz

java17和java8一样,都是LTS长期支持版本,因此这里直接下载java17

2、解压安装包,修改包名为jdk-17
tar zxf jdk-17_linux-x64_bin.tar.gz
rm -rf jdk-17_linux-x64_bin.tar.gz
mv jdk-17.0.3.1 jdk-17
3、移动文件夹到/usr/local下
mv jdk-17 /usr/local/
4、将java添加到环境变量中
vi /etc/profile
export JAVA_HOME=/usr/local/jdk-17
export PATH=/usr/local/php/bin:/usr/local/jdk-17/bin:$PATH
5、加载刚才修改的文件
source /etc/profile
6、验证是否安装java成功
java -version

显示下面内容,说明安装成功

[root@v2 jdk-17]# java -version
java version "17" 2021-09-14 LTS
Java(TM) SE Runtime Environment (build 17+35-LTS-2724)
Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)