文章目录
- 一、卸载openjdk
- 1. 查看openjdk版本
- 2. 卸载openjdk
- 二、下载jdk1.8
- 三、安装jdk1.8
- 方法一、手动配置
- 1. 准备jdk文件
- 2. 配置`/etc/profile`
- 3. 使`/etc/profile`生效
- 方法二、安装二进制包
- 1. 安装rpm包
- 2. 配置`/etc/profile`
- 3. 使`/etc/profile`生效
- 题外话:安装openJDK
一、卸载openjdk
1. 查看openjdk版本
[nangy@nangy-vm ~]$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
[nangy@nangy-vm ~]$ rpm -qa | grep java
java-1.7.0-openjdk-headless-1.7.0.231-2.6.19.1.el7_6.x86_64
javapackages-tools-3.4.1-11.el7.noarch
java-1.8.0-openjdk-headless-1.8.0.222.b10-0.el7_6.x86_64
python-javapackages-3.4.1-11.el7.noarch
tzdata-java-2019b-1.el7.noarch
java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64
java-1.7.0-openjdk-1.7.0.231-2.6.19.1.el7_6.x86_64
2. 卸载openjdk
使用rpm -e --nodeps
进行强制卸载,将所有的openjdk都nodeps
掉
[nangy@nangy-vm ~]$ sudo rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.231-2.6.19.1.el7_6.x86_64
[nangy@nangy-vm ~]$ sudo rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.222.b10-0.el7_6.x86_64
[nangy@nangy-vm ~]$ sudo rpm -e --nodeps java-1.8.0-openjdk-1.8.0.222.b10-0.el7_6.x86_64
[nangy@nangy-vm ~]$ sudo rpm -e --nodeps java-1.7.0-openjdk-1.7.0.231-2.6.19.1.el7_6.x86_64
# 验证一下
[nangy@nangy-vm ~]$ java -version
bash: /usr/bin/java: 没有那个文件或目录
二、下载jdk1.8
三、安装jdk1.8
方法一、手动配置
1. 准备jdk文件
先下载*.tar.gz
压缩包
[nangy@nangy-vm ~]$ sudo mkdir /opt/java
[nangy@nangy-vm ~]$ ll /opt/ | grep java
drwxr-xr-x. 2 root root 6 8月 20 16:47 java
[nangy@nangy-vm ~]$ cd /opt/java/
[nangy@nangy-vm java]$ sudo cp /mnt/hgfs/VMware共享文件/software/jdk-8u211-linux-x64.tar.gz -R /opt/java/
[nangy@nangy-vm java]$ ll
总用量 190424
-rwxr-xr-x. 1 root root 194990602 8月 20 16:48 jdk-8u211-linux-x64.tar.gz
[nangy@nangy-vm java]$ sudo tar -zxvf jdk-8u211-linux-x64.tar.gz
[nangy@nangy-vm java]$ cd jdk1.8.0_211/
[nangy@nangy-vm jdk1.8.0_211]$ pwd
/opt/java/jdk1.8.0_211
2. 配置/etc/profile
[nangy@nangy-vm jdk1.8.0_211]$ sudo vim /etc/profile
- 将变量配置添加到
/etc/profile
尾部
# JAVA_HOME
export JAVA_HOME=/opt/java/jdk1.8.0_211
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
3. 使/etc/profile生效
# 切换到root用户
[nangy@nangy-vm jdk1.8.0_211]$ su
[root@nangy-vm jdk1.8.0_211]$ source /etc/profile
[root@nangy-vm jdk1.8.0_211]$ 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)
方法二、安装二进制包
1. 安装rpm包
先下载*.rpm
二进制包
[nangy@nangy-vm 下载]$ sudo rpm -ivh jdk-8u211-linux-x64.rpm
[nangy@nangy-vm 下载]$ 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)
2. 配置/etc/profile
[nangy@nangy-vm 下载]$ sudo vim /etc/profile
- 将变量配置添加到
/etc/profile
尾部
通过rpm包安装的jdk路径是/usr/java/jdk1.8.0_211-amd64
# JAVA_HOME
export JAVA_HOME=/usr/java/jdk1.8.0_211-amd64
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH
3. 使/etc/profile生效
# 切换到root用户
[nangy@nangy-vm 下载]$ su
[root@nangy-vm 下载]$ source /etc/profile
[root@nangy-vm 下载]$ 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)
题外话:安装openJDK
# 查看可用的JDK软件包列表
[nangy@nangy-vm ~]$ sudo yum search java | grep -i --color JDK
# 输入以下命令yum安装openjdk
[nangy@nangy-vm ~]$ sudo yum install java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64