一、删除自带openjdk
首先查看系统中是否有已安装的jdk
[root@bogon opt]# 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)查找所有jdk相关的安装文件
[root@bogon opt]# rpm -qa | grep jdk copy-jdk-configs-1.2-1.el7.noarch java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64 java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64 java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64 java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64删除全部jdk相关文件即可
[root@bogon opt]# rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64 java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64 [root@bogon opt]# rpm -qa | grep jdk 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 [root@bogon opt]# rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64 java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64检查有没有删除
[root@bogon opt]# java -version -bash: /usr/bin/java: 没有那个文件或目录二、安装自定义jdk
从官网下载jdk安装包
链接:
用rz命令把安装包上传到服务器/software目录下,没有安装的执行下面命令即可安装该工具
yum -y install lrzsz安装包解压到/opt目录下
[root@bogon opt]# tar -xzvf jdk-8u172-linux-x64.tar.gz配置环境变量
局部环境变量:~.bash_profile
全局环境变量:/etc/profile
配置内容(文件末尾追加):export JAVA_HOME=http://www.likecs.com/opt/jdk1.8.0_172 export PATH=$PATH:$JAVA_HOME/bin使配置生效
[root@bogon opt]# source /etc/profile验证环境变量是否生效
[root@bogon opt]# echo $JAVA_HOME /opt/jdk1.8.0_172 [root@bogon opt]# echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/software/mindoc/lib/time/zoneinfo.zip:/root/bin:/software/mindoc/lib/time/zoneinfo.zip:/opt/jdk1.8.0_172/bin:/software/mindoc/lib/time/zoneinfo.zip:/opt/jdk1.8.0_172/bin验证jdk安装成功与否
[root@bogon opt]# java -version java version "1.8.0_172" Java(TM) SE Runtime Environment (build 1.8.0_172-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)