一:卸载系统自带安装的JDK

注:本文参考了《 使用CentOS7卸载自带jdk安装自己的JDK1.8

通过xshell工具成功连接安装好的虚拟机之后可通过    rpm -qa | grep Java  命令来查询出系统自带的jdk(带箭头的四个就是系统自带的)注:不带箭头的那三个不要删掉

然后通过    rpm -e --nodeps   后面跟系统自带的jdk名    这个命令来删除系统自带的jdk,

例如:rpm -e --nodeps java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64
           rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
           rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64
           rpm -e --nodeps java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64

删完之后可以再通过    rpm -qa | grep Java  命令来查询出是否删除掉

二:Centos7 通过yum命令安装jdk1.8

注:本段内容参考了《Centos7 通过yum命令安装jdk1.8

先查看系统有没有自带的openjdk

rpm -qa |grep java
rpm -qa |grep jdk
rpm -qa |grep gcj
[root@localhost java]# rpm -qa | grep java
tzdata-java-2016g-2.el7.noarch
python-javapackages-3.4.1-11.el7.noarch
[root@localhost java]# rpm -qa |grep jdk
copy-jdk-configs-1.2-1.el7.noarch
[root@localhost java]# rpm -qa |grep gcj
[root@localhost java]#

如果安装了,首先卸载

批量卸载

rpm -qa | grep java | xargs rpm -e –nodeps

检索yum中有没有java1.8的包

yum list java-1.8*   

开始安装

yum install java-1.8.0-openjdk* -y
[root@localhost java]# yum install java-1.8.0-openjdk* -y
Loaded plugins: fastestmirror, langpacks
file://yum/mnt/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/repodata/repomd.xml"
Trying other mirror.
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.102-4.b14.el7 will be installed
--> Processing Dependency: java-atk-wrapper for package: 1:java-1.8.0-openjdk-accessibility-1.8.0.102-4.b14.el7.x86_64
---> Package java-1.8.0-openjdk-accessibility-debug.x86_64 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-debug.x86_64 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-demo.x86_64 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-devel.x86_64 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-headless.x86_64 1:1.8.0.102-4.b14.el7 will be installed
--> Processing Dependency: jpackage-utils for package: 1:java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64
---> Package java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-javadoc-zip-debug.noarch 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-src.x86_64 1:1.8.0.102-4.b14.el7 will be installed
---> Package java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.102-4.b14.el7 will be installed
--> Running transaction check
---> Package java-atk-wrapper.x86_64 0:0.30.4-5.el7 will be installed
---> Package javapackages-tools.noarch 0:3.4.1-11.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================
Package Arch Version Repository Size
============================================================================================================================================================================
Installing:
java-1.8.0-openjdk x86_64 1:1.8.0.102-4.b14.el7 c7-media 230 k
java-1.8.0-openjdk-accessibility x86_64 1:1.8.0.102-4.b14.el7 c7-media 38 k
java-1.8.0-openjdk-accessibility-debug x86_64 1:1.8.0.102-4.b14.el7 c7-media 38 k
java-1.8.0-openjdk-debug x86_64 1:1.8.0.102-4.b14.el7 c7-media 234 k
java-1.8.0-openjdk-demo x86_64 1:1.8.0.102-4.b14.el7 c7-media 1.9 M
java-1.8.0-openjdk-demo-debug x86_64 1:1.8.0.102-4.b14.el7 c7-media 2.0 M
java-1.8.0-openjdk-devel x86_64 1:1.8.0.102-4.b14.el7 c7-media 9.7 M
java-1.8.0-openjdk-devel-debug x86_64 1:1.8.0.102-4.b14.el7 c7-media 9.7 M
java-1.8.0-openjdk-headless x86_64 1:1.8.0.102-4.b14.el7 c7-media 31 M
java-1.8.0-openjdk-headless-debug x86_64 1:1.8.0.102-4.b14.el7 c7-media 32 M
java-1.8.0-openjdk-javadoc noarch 1:1.8.0.102-4.b14.el7 c7-media 15 M
java-1.8.0-openjdk-javadoc-debug noarch 1:1.8.0.102-4.b14.el7 c7-media 15 M
java-1.8.0-openjdk-javadoc-zip noarch 1:1.8.0.102-4.b14.el7 c7-media 41 M
java-1.8.0-openjdk-javadoc-zip-debug noarch 1:1.8.0.102-4.b14.el7 c7-media 41 M
java-1.8.0-openjdk-src x86_64 1:1.8.0.102-4.b14.el7 c7-media 45 M
java-1.8.0-openjdk-src-debug x86_64 1:1.8.0.102-4.b14.el7 c7-media 45 M
Installing for dependencies:
java-atk-wrapper x86_64 0.30.4-5.el7 c7-media 71 k
javapackages-tools noarch 3.4.1-11.el7 c7-media 73 k Transaction Summary
============================================================================================================================================================================
Install 16 Packages (+2 Dependent packages) Total download size: 290 M
Installed size: 1.0 G
Downloading packages:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 71 MB/s | 290 MB 00:00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
** Found 14 pre-existing rpmdb problem(s), 'yum check' output follows:
icedtea-web-1.6.2-4.el7.x86_64 has missing requires of java-1.8.0-openjdk
icedtea-web-1.6.2-4.el7.x86_64 has missing requires of jpackage-utils
icedtea-web-1.6.2-4.el7.x86_64 has missing requires of jpackage-utils
ipa-client-4.4.0-12.el7.centos.x86_64 has installed conflicts freeipa-client: ipa-client-4.4.0-12.el7.centos.x86_64
ipa-client-common-4.4.0-12.el7.centos.noarch has installed conflicts freeipa-client-common: ipa-client-common-4.4.0-12.el7.centos.noarch
ipa-common-4.4.0-12.el7.centos.noarch has installed conflicts freeipa-common: ipa-common-4.4.0-12.el7.centos.noarch
jline-1.0-8.el7.noarch has missing requires of java >= ('0', '1.5', None)
jline-1.0-8.el7.noarch has missing requires of jpackage-utils
1:libreoffice-core-5.0.6.2-3.el7.x86_64 has missing requires of java-headless >= ('1', '1.6', None)
1:libreoffice-ure-5.0.6.2-3.el7.x86_64 has missing requires of libjvm.so()(64bit)
rhino-1.7R4-5.el7.noarch has missing requires of jpackage-utils
rhino-1.7R4-5.el7.noarch has missing requires of jpackage-utils
tagsoup-1.2.1-8.el7.noarch has missing requires of jpackage-utils
tagsoup-1.2.1-8.el7.noarch has missing requires of jpackage-utils >= ('0', '1.6', None)
Installing : javapackages-tools-3.4.1-11.el7.noarch 1/18
Installing : 1:java-1.8.0-openjdk-headless-debug-1.8.0.102-4.b14.el7.x86_64 2/18
Installing : 1:java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64 3/18
Installing : 1:java-1.8.0-openjdk-devel-1.8.0.102-4.b14.el7.x86_64 4/18
Installing : 1:java-1.8.0-openjdk-debug-1.8.0.102-4.b14.el7.x86_64 5/18
Installing : 1:java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64 6/18
Installing : java-atk-wrapper-0.30.4-5.el7.x86_64 7/18
Installing : 1:java-1.8.0-openjdk-accessibility-debug-1.8.0.102-4.b14.el7.x86_64 8/18
Installing : 1:java-1.8.0-openjdk-accessibility-1.8.0.102-4.b14.el7.x86_64 9/18
Installing : 1:java-1.8.0-openjdk-demo-1.8.0.102-4.b14.el7.x86_64 10/18
Installing : 1:java-1.8.0-openjdk-devel-debug-1.8.0.102-4.b14.el7.x86_64 11/18
Installing : 1:java-1.8.0-openjdk-demo-debug-1.8.0.102-4.b14.el7.x86_64 12/18
Installing : 1:java-1.8.0-openjdk-src-1.8.0.102-4.b14.el7.x86_64 13/18
Installing : 1:java-1.8.0-openjdk-javadoc-1.8.0.102-4.b14.el7.noarch 14/18
Installing : 1:java-1.8.0-openjdk-javadoc-zip-1.8.0.102-4.b14.el7.noarch 15/18
Installing : 1:java-1.8.0-openjdk-src-debug-1.8.0.102-4.b14.el7.x86_64 16/18
Installing : 1:java-1.8.0-openjdk-javadoc-zip-debug-1.8.0.102-4.b14.el7.noarch 17/18
Installing : 1:java-1.8.0-openjdk-javadoc-debug-1.8.0.102-4.b14.el7.noarch 18/18
Verifying : 1:java-1.8.0-openjdk-accessibility-debug-1.8.0.102-4.b14.el7.x86_64 1/18
Verifying : java-atk-wrapper-0.30.4-5.el7.x86_64 2/18
Verifying : 1:java-1.8.0-openjdk-accessibility-1.8.0.102-4.b14.el7.x86_64 3/18
Verifying : 1:java-1.8.0-openjdk-debug-1.8.0.102-4.b14.el7.x86_64 4/18
Verifying : 1:java-1.8.0-openjdk-devel-1.8.0.102-4.b14.el7.x86_64 5/18
Verifying : 1:java-1.8.0-openjdk-headless-debug-1.8.0.102-4.b14.el7.x86_64 6/18
Verifying : 1:java-1.8.0-openjdk-src-debug-1.8.0.102-4.b14.el7.x86_64 7/18
Verifying : 1:java-1.8.0-openjdk-demo-1.8.0.102-4.b14.el7.x86_64 8/18
Verifying : 1:java-1.8.0-openjdk-devel-debug-1.8.0.102-4.b14.el7.x86_64 9/18
Verifying : 1:java-1.8.0-openjdk-src-1.8.0.102-4.b14.el7.x86_64 10/18
Verifying : 1:java-1.8.0-openjdk-javadoc-zip-debug-1.8.0.102-4.b14.el7.noarch 11/18
Verifying : 1:java-1.8.0-openjdk-demo-debug-1.8.0.102-4.b14.el7.x86_64 12/18
Verifying : 1:java-1.8.0-openjdk-javadoc-1.8.0.102-4.b14.el7.noarch 13/18
Verifying : javapackages-tools-3.4.1-11.el7.noarch 14/18
Verifying : 1:java-1.8.0-openjdk-javadoc-zip-1.8.0.102-4.b14.el7.noarch 15/18
Verifying : 1:java-1.8.0-openjdk-javadoc-debug-1.8.0.102-4.b14.el7.noarch 16/18
Verifying : 1:java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64 17/18
Verifying : 1:java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64 18/18 Installed:
java-1.8.0-openjdk.x86_64 1:1.8.0.102-4.b14.el7 java-1.8.0-openjdk-accessibility.x86_64 1:1.8.0.102-4.b14.el7
java-1.8.0-openjdk-accessibility-debug.x86_64 1:1.8.0.102-4.b14.el7 java-1.8.0-openjdk-debug.x86_64 1:1.8.0.102-4.b14.el7
java-1.8.0-openjdk-demo.x86_64 1:1.8.0.102-4.b14.el7 java-1.8.0-openjdk-demo-debug.x86_64 1:1.8.0.102-4.b14.el7
java-1.8.0-openjdk-devel.x86_64 1:1.8.0.102-4.b14.el7 java-1.8.0-openjdk-devel-debug.x86_64 1:1.8.0.102-4.b14.el7
java-1.8.0-openjdk-headless.x86_64 1:1.8.0.102-4.b14.el7 java-1.8.0-openjdk-headless-debug.x86_64 1:1.8.0.102-4.b14.el7
java-1.8.0-openjdk-javadoc.noarch 1:1.8.0.102-4.b14.el7 java-1.8.0-openjdk-javadoc-debug.noarch 1:1.8.0.102-4.b14.el7
java-1.8.0-openjdk-javadoc-zip.noarch 1:1.8.0.102-4.b14.el7 java-1.8.0-openjdk-javadoc-zip-debug.noarch 1:1.8.0.102-4.b14.el7
java-1.8.0-openjdk-src.x86_64 1:1.8.0.102-4.b14.el7 java-1.8.0-openjdk-src-debug.x86_64 1:1.8.0.102-4.b14.el7 Dependency Installed:
java-atk-wrapper.x86_64 0:0.30.4-5.el7 javapackages-tools.noarch 0:3.4.1-11.el7 Complete!
[root@localhost java]#

验证是否安装成功
查看jdk版本

java -version

返回的信息

[root@localhost java]# 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)
[root@localhost java]#

安装成功!!!

此时,如果使用javac,java都是可以的。我们还没有设置环境变量,为什么直接可以使用了呢?

这就体现出了在线安装的好处了,它会自动配置环境变量,我们通过echo $PATH命令查看

echo $PATH
[root@localhost java]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@localhost java]#

“:”为Linux系统中环境变量分割符。

如何查看jdk的JAVA_HOME?

[root@localhost java]# whereis javac
javac: /usr/bin/javac /usr/share/man/man1/javac.1.gz
[root@localhost java]#
[root@localhost java]# whereis javac
javac: /usr/bin/javac /usr/share/man/man1/javac.1.gz
[root@localhost java]# ls -al /usr/bin/javac
lrwxrwxrwx. 1 root root 23 Jul 19 00:59 /usr/bin/javac -> /etc/alternatives/javac
[root@localhost java]# ls -al /etc/alternatives/javac
lrwxrwxrwx. 1 root root 68 Jul 19 00:59 /etc/alternatives/javac -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64/bin/javac
[root@localhost java]# ls -al /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64/bin/javac
-rwxr-xr-x. 1 root root 7384 Nov 12 2016 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64/bin/javac
[root@localhost java]#

此时说明
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.102-1.b14.el7_2.x86_64/bin/javac
是一个真实的地址。

所以
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.102-1.b14.el7_2.x86_64/
就是JAVA_HOME

将JAVA_HOME加入环境变量

可以添加到rc文件,比如
/etc/rc.d/rc.local
1.使用vim
(不再介绍)
或者
2.使用
echo >> 命令

jhometip='# add JAVA_HOME'
jhomescript='export JAVA_HOME=/etc/alternatives/java_sdk_1.8.0'
sudo echo $jhometip >> /etc/rc.d/rc.local
sudo echo $jhomescript >> /etc/rc.d/rc.local

/etc/alternatives/java_sdk_1.8.0
是一个软链接,直接指向JAVA_HOME地址。

Centos7 linux 卸载自带安装的jdk 并yum自动安装jdk1.8的更多相关文章

  1. WordPress安装篇(4):YUM方式安装LNMP并部署WordPress

    YUM方式安装软件的优点就是简单.方便.快捷,本文介绍在Linux上如何使用YUM方式快速安装LNMP并部署WordPress.使用Linux CentOS 7.9 + Nginx 1.18 + My ...

  2. 让CentOS能用yum自动安装rar和unrar

    目的:让CentOS能用yum自动安装rar和unrar 系统环境: CentOS 7.0 具体操作步骤如下: 1.编辑文件 编辑dag.repo文件,或者说是新建一个dag.repo文件. vi / ...

  3. CentOS6.x/6.5/6.4/6.3/6.2/7.x 64位安装php5.2(使用YUM自动安装)

    默认情况下,CentOS6 64 bit 已经早已不支持php5.2.x ,但是某些php程序还需要zend optimizer支持,怎么办呢?目前大部分的yum repos 都已经不支持直接安装ph ...

  4. CentOS7系统卸载自带的OpenJDK并安装SUNJDK

    安装说明 系统环境: CentOS 7 安装方式: rmp安装 软件: jdk-8u111-linux-x64.rpm 下载地址: Oracle JDK 官网下载地址 卸载CentOS默认安装的Ope ...

  5. linux 卸载自带apache httpd 安装apache httpd

    一.卸载自带apache httpd 1.关闭httpd服务:/etc/init.d/httpd stop 2.列出相关程序包:rpm -qa|grep httpd 3.卸载命令:rpm -e --n ...

  6. 实用脚本----Linux下Jdk和Tomcat自动安装shell脚本总结

    系统环境为:ubuntu 14.04 一.JDK 自动安装脚本 jdk自动安装bash shell脚本,截止今天(2014/10/15)亲测可用: sudo su #切换到root权限 mkdir / ...

  7. 关于linux下mysql 5.7.x数据库的yum的安装方法

    环境介绍>>>>>>>>>>>>>>>>>> 操作系统:Centos 7.1 mysql数据 ...

  8. kickstart半自动安装centos系统与pxe自动安装centos系统

    一.kickstart半自动安装centos系统 关闭防火墙,关闭selinux,使用system-config-kickstart生成kickstart配置文件,启动xmanger-Passive ...

  9. 【无法使用yum安装软件】使用yum命令安装软件提示No package numactl.x86_64 available.

    在安装mysql时需要安装numactl.x86_64 使用yum -y install numactl.x86_64时报错 [root@sdp6 mysql]# yum -y install num ...

随机推荐

  1. loj 10050 连续子段最大异或和

    #include<bits/stdc++.h> #define rep(i,x,y) for(register int i=x;i<=y;i++) using namespace s ...

  2. iOS拍照图片旋转的问题

    很久之前,遇到了这种情况,iOS某端拍照上传到服务器,其他iOS端从服务器下载该照片展示,发现图片逆时针旋转了90度.当时百度了一下,找到一段代码修正image方向,问题解决了,但没有深入理解底层原理 ...

  3. 理解JS的执行环境

    执行环境(Execution context,EC)或执行上下文,是JS中一个极为重要的概念 EC的组成 当JavaScript代码执行的时候,会进入不同的执行上下文,这些执行上下文会构成了一个执行上 ...

  4. linux 截图工具 shutter

    ubuntu 安装shutter sudo apt install shutter libgoo-canvas-perl libgoo-canvas-perl是提供对截图编辑功能,例如,添加画框,文字 ...

  5. intellij idea无效的发型版本1.8解决方案

    描述:intellj中启动项目报错无效的发行版本:8 解决方案一: file -> settings -> build,exception,deployment -> compile ...

  6. hystrix学习

      概述: 字面意思是豪猪.作用是保护你的应用.Netflix会有服务实时调用,hystrix提供服务降级. 目标是将依赖独立化,防止拖垮整个服务.(属于降级服务.) 作用: 第三方接口超时或失败时, ...

  7. Java学习过程中要记录的地方--汇总

    1.Map的子类 HashMap 是哈希表,根据哈希算法来存的,取出来不一定是按照原来的循序: Ctrl+T 可以看到 HashMap下面有 LinkHashMap 是线性实现的,里面有顺序. --- ...

  8. vue中如何让多个echarts随屏幕大小变化

    在vue项目中使用Echarts  一般window.onsize在页面中只能存在一个. 如何在一个页面中多个echarts使用window.onresize?    myChart 可以放在Data ...

  9. 20165221学习基础和C语言基础调查

    1.你有什么技能比大多人(超过90%以上)更好? - 我觉得自己应该改算资质平平的那种人,如果说有什么技能比大多数人更好,我觉得应该是看过自己喜欢的书后,那种记忆能力.就比如自己从小对历史很感兴趣,小 ...

  10. 论文笔记:Deep Residual Learning

    之前提到,深度神经网络在训练中容易遇到梯度消失/爆炸的问题,这个问题产生的根源详见之前的读书笔记.在 Batch Normalization 中,我们将输入数据由激活函数的收敛区调整到梯度较大的区域, ...