美文网首页
阿里云centos7.4安装和卸载OracleJDK1.8

阿里云centos7.4安装和卸载OracleJDK1.8

作者: nextliving | 来源:发表于2018-04-22 15:15 被阅读125次

    自己的阿里云ecs上装的系统是centos7.4,一般默认安装了open jdk.但是事实上很多应用软件可能对oracle jdk的支持更好,因此将open jdk换成oracle jdk8.

    检查已存在java版本

    查看java版本

    使用命令$ java -version查看版本信息:

    
    -bash: java: command not found
    
    

    说明系统中没有安装java.

    查看jdk版本

    使用命令$ rpm -qa | grep java$ rpm -qa | grep java查看jdk信息,没有输出任何内容,说明系统中没有任何的jdk的yum源.

    总结

    之前在自己的电脑中的虚拟机中安装的centos7是带open jdk的,这次阿里云上却没有.个人分析是因为自己在虚拟机中安装的时候勾选了比较多的选项,导致open jdk也被安装.而阿里云是面向无数用户,因此提供的centos是最纯净的版本,方便用户按需安装.

    安装oracle jdk1.8

    下载jdk1.8

    使用wget命令下载:

    $ wget --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.rpm

    注意: wget后面的header必须带上,否则一定会下载失败,我自己第一次就是因为没加header部分导致失败了.http部分对应的url根据版本会有变化,可以去Oracle官网Java SE Development Kit 8 Downloads获取.

    输出

    --2018-12-27 13:46:15--  https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.rpm
    Resolving download.oracle.com (download.oracle.com)... 69.192.9.199
    Connecting to download.oracle.com (download.oracle.com)|69.192.9.199|:443... connected.
    HTTP request sent, awaiting response... 302 Moved Temporarily
    Location: https://edelivery.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.rpm [following]
    --2018-12-27 13:46:15--  https://edelivery.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.rpm
    Resolving edelivery.oracle.com (edelivery.oracle.com)... 184.26.250.202, 2600:1417:76:19a::2d3e, 2600:1417:76:181::2d3e
    Connecting to edelivery.oracle.com (edelivery.oracle.com)|184.26.250.202|:443... connected.
    HTTP request sent, awaiting response... 302 Moved Temporarily
    Location: http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.rpm?AuthParam=1545889696_3518430c799be5fff3fcd3909a875c61 [following]
    --2018-12-27 13:46:16--  http://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.rpm?AuthParam=1545889696_3518430c799be5fff3fcd3909a875c61
    Connecting to download.oracle.com (download.oracle.com)|69.192.9.199|:80... connected.
    HTTP request sent, awaiting response... 301 Moved Permanently
    Location: https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.rpm?AuthParam=1545889696_3518430c799be5fff3fcd3909a875c61 [following]
    --2018-12-27 13:46:16--  https://download.oracle.com/otn-pub/java/jdk/8u191-b12/2787e4a523244c269598db4e85c51e0c/jdk-8u191-linux-x64.rpm?AuthParam=1545889696_3518430c799be5fff3fcd3909a875c61
    Connecting to download.oracle.com (download.oracle.com)|69.192.9.199|:443... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 176154027 (168M) [application/x-redhat-package-manager]
    Saving to: ‘jdk-8u191-linux-x64.rpm’
    
    100%[==============================================================================================================>] 176,154,027 9.21MB/s   in 18s    
    
    2018-12-27 13:46:35 (9.24 MB/s) - ‘jdk-8u191-linux-x64.rpm’ saved [176154027/176154027]
    
    

    安装

    执行

    $ rpm -ivh jdk-8u191-linux-x64.rpm

    输出

    warning: jdk-8u191-linux-x64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:jdk1.8-2000:1.8.0_191-fcs        ################################# [100%]
    Unpacking JAR files...
        tools.jar...
        plugin.jar...
        javaws.jar...
        deploy.jar...
        rt.jar...
        jsse.jar...
        charsets.jar...
        localedata.jar...
    

    此时再执行命令$ java -version查看:

    
    java version "1.8.0_191"
    Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
    Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)
    
    

    执行命令$ rpm -qa | grep jdk输出

    jdk1.8-1.8.0_191-fcs.x86_64

    可见已经安装成功.

    JDK会被默认安装在/usr/java中,执行$ cd /usr/java去/usr/java文件夹中,执行$ ls输出

    
    default    jdk1.8.0_191-amd64     latest
    
    
    

    配置环境变量

    环境变量的配置在/etc/profile文件中,$ vi /etc/profile在文件末尾添加下面的内容:

    
    export JAVA_HOME=/usr/java/jdk1.8.0_191-amd64
    
    export PATH=$JAVA_HOME/bin:$PATH
    
    

    卸载jdk1.8

    既然可以安装,那么该怎么卸载呢?首先执行$ rpm -qa | grep jdk输出jdk1.8-1.8.0_162-fcs.x86_64,说明jdk1.8-1.8.0_162-fcs.x86_64就是需要卸载的对象.

    执行rpm -ev jdk1.8-1.8.0_162-fcs.x86_64卸载:

    
    Preparing packages...
    
    jdk1.8-2000:1.8.0_162-fcs.x86_64
    
    

    此时再执行$ java -version输出

    
    -bash: /usr/bin/java: No such file or directory
    
    

    执行$ rpm -qa | grep jdk不输出任何内容.并且$ cd /usr/java中执行$ ls中不再输出任何内容,说明已经彻底卸载.

    参考

    相关文章

      网友评论

          本文标题:阿里云centos7.4安装和卸载OracleJDK1.8

          本文链接:https://www.haomeiwen.com/subject/nfkclftx.html