-
下载JDK的源码压缩包
假设JDK的下载后的文件名是jdk-8u211-linux-x64.tar.gz -
切换到root用户,查看本机是否已安装JDK,CentOS 7默认安装了OpenJDK
[root@localhost ~]# rpm -qa|grep 'jdk'
java-1.7.0-openjdk-1.7.0.191-2.6.15.5.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.191-2.6.15.5.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.181-7.b13.el7.x86_64
java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64
copy-jdk-configs-3.3-10.el7_5.noarch
- 如果已安装JDK,需要先用rpm命令卸载
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.191-2.6.15.5.el7.x86_64
[root@localhost ~]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.191-2.6.15.5.el7.x86_64
[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64
[root@localhost ~]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.181-7.b13.el7.x86_64
[root@localhost ~]# rpm -e --nodeps copy-jdk-configs-3.3-10.el7_5.noarch
- 上传JDK的源码压缩包然后解压缩
[root@localhost ~]# tar -xzvf jdk-8u211-linux-x64.tar.gz
- 因为jdk的目录名较长,可以改名移动/usr/local目录
[root@localhost ~]# mv jdk1.8.0_211 /usr/local/jdk
- 设置JAVA_HOME和PATH环境变量
[root@localhost ~]# vi /etc/profile.d/jdk.sh
输入下面两行内容保存退出
export JAVA_HOME=/usr/local/jdk
export PATH=$PATH:$JAVA_HOME/bin
- 增加环境变量脚本执行权限并执行脚本
[root@localhost ~]# chmod +x /etc/profile.d/jdk.sh
[root@localhost ~]# source /etc/profile.d/jdk.sh
- 验证JDK安装是否成功
[root@localhost ~]# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
网友评论