环境信息
CentOS Linux release 7.4.1708 (Core)
jdk1.8.0_172
卸载OpenJDK
在终端运行命令,查看是否有安装OpenJDK
[vagrant@localhost ~]$ java -version openjdk version "1.8.0_161" OpenJDK Runtime Environment (build 1.8.0_161-b14) OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
如果已经存在了openjdk,查询需要卸载的内容
[vagrant@localhost ~]$ rpm -qa | grep openjdk java-1.7.0-openjdk-headless-1.7.0.171-2.6.13.0.el7_4.x86_64 java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64 java-1.7.0-openjdk-1.7.0.171-2.6.13.0.el7_4.x86_64 java-1.8.0-openjdk-headless-1.8.0.161-0.b14.el7_4.x86_64
根据第二步查询的要卸载的内容,使用命令
rpm -e --nodeps
进行卸载
[vagrant@localhost ~]$ sudo rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.171-2.6.13.0.el7_4.x86_64
[vagrant@localhost ~]$ sudo rpm -e --nodeps java-1.8.0-openjdk-1.8.0.161-0.b14.el7_4.x86_64
[vagrant@localhost ~]$ sudo rpm -e --nodeps java-1.7.0-openjdk-1.7.0.171-2.6.13.0.el7_4.x86_64
[vagrant@localhost ~]$ sudo rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.161-0.b14.el7_4.x86_64
安装SunJDK
在家目录下创建一个文件夹,并进入
[vagrant@localhost ~]$ mkdir java [vagrant@localhost ~]$ cd java
下载SunJDK,得到文件jdk-8u172-linux-x64.tar.gz
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u172-b11/a58eab1ec242421181065cdc37240b08/jdk-8u172-linux-x64.tar.gz
[vagrant@localhost java]$ ls jdk-8u172-linux-x64.tar.gz
- 解压JDK
tar -zxvf jdk-8u172-linux-x64.tar.gz
配置JDK环境变量
在终端输入命令
vim /etc/profile
在文本最后加上下面的内容
#java environment export JAVA_HOME=/home/vagrant/java/jdk1.8.0_172 export CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/dt.jar:${JAVA_HOME}/lib/tools.jar export PATH=$PATH:${JAVA_HOME}/bin
使配置生效
source /etc/profile
测试安装
- 运行命令
[vagrant@localhost jdk1.8.0_172]$ 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)