1、首先查看系统中是否已安装jdk
[root@VM-12-6-centos jdk1.8.0_201]# java -version
显示如下:
openjdk version "1.8.0_102"
OpenJDK Runtime Environment (build 1.8.0_102-b14)
OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)
2、卸载已安装的
首先检测安装包:
[root@VM-12-6-centos software]# rpm -qa | grep java
显示如下:
java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2016g-2.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
卸载:
[root@VM-12-6-centos software]# rpm -e --nodeps tzdata-java-2016g-2.el7.noarch
[root@VM-12-6-centos software]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111- 2.6.7.8.el7.x86_64
[root@VM-12-6-centos software]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
[root@VM-12-6-centos software]# rpm -e --nodeps java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
[root@VM-12-6-centos software]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
之后再次输入rpm -qa | grep java 查看卸载情况:
[root@VM-12-6-centos software]# rpm -qa | grep java
python-javapackages-3.4.1-11.el7.noarch
javapackages-tools-3.4.1-11.el7.noarch
3、安装jdk
首先到官网下载需要的JDK版本,在这里我已经下载好jdk,在此省略此步骤
将jdk包上传到系统中指定的目录,在这里我们将jdk包上传到/usr/local目录下
进入该目录:
[root@VM-12-6-centos jdk1.8.0_201]# cd /usr/local/
解压jdk-8u201-linux-x64.tar.gz安装包到指定目录:
[root@VM-12-6-centos local]# tar -zxvf jdk-8u201-linux-x64.tar.gz -C /java
设置环境变量:
[root@VM-12-6-centos java]# vim /etc/profile
在最前面添加:
export JAVA_HOME=/java/jdk1.8.0_201
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
执行profile文件:
[root@VM-12-6-centos java]# source /etc/profile
这样可以使配置文件立即生效
4、检测JDK是否安装成功
执行命令:
[root@VM-12-6-centos java]# java -version
出现以下结果则JDK安装成功:
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
至此,JDK安装结束。
相关文章
暂无评论...