• 阿里云 linux centos7下安装JDK


    一、安装JDK

    1、查看可用的JDK版本

    yum -y list java*

    结果如下:

    Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
    Available Packages
    java-1.6.0-openjdk.x86_64                                                               1:1.6.0.41-1.13.13.1.el7_3                                         os     
    java-1.6.0-openjdk-demo.x86_64                                                          1:1.6.0.41-1.13.13.1.el7_3                                         os     
    java-1.6.0-openjdk-devel.x86_64                                                         1:1.6.0.41-1.13.13.1.el7_3                                         os     
    java-1.6.0-openjdk-javadoc.x86_64                                                       1:1.6.0.41-1.13.13.1.el7_3                                         os     
    java-1.6.0-openjdk-src.x86_64                                                           1:1.6.0.41-1.13.13.1.el7_3                                         os     
    java-1.7.0-openjdk.x86_64                                                               1:1.7.0.261-2.6.22.2.el7_8                                         os     
    java-1.7.0-openjdk-accessibility.x86_64                                                 1:1.7.0.261-2.6.22.2.el7_8                                         os     
    java-1.7.0-openjdk-demo.x86_64                                                          1:1.7.0.261-2.6.22.2.el7_8                                         os     
    java-1.7.0-openjdk-devel.x86_64                                                         1:1.7.0.261-2.6.22.2.el7_8                                         os     
    java-1.7.0-openjdk-headless.x86_64                                                      1:1.7.0.261-2.6.22.2.el7_8                                         os     
    java-1.7.0-openjdk-javadoc.noarch                                                       1:1.7.0.261-2.6.22.2.el7_8                                         os     
    java-1.7.0-openjdk-src.x86_64                                                           1:1.7.0.261-2.6.22.2.el7_8                                         os     
    java-1.8.0-openjdk.i686                                                                 1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk.x86_64                                                               1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk-accessibility.i686                                                   1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk-accessibility.x86_64                                                 1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk-demo.i686                                                            1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk-demo.x86_64                                                          1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk-devel.i686                                                           1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk-devel.x86_64                                                         1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk-headless.i686                                                        1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk-headless.x86_64                                                      1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk-javadoc.noarch                                                       1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk-javadoc-zip.noarch                                                   1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk-src.i686                                                             1:1.8.0.292.b10-1.el7_9                                            updates
    java-1.8.0-openjdk-src.x86_64                                                           1:1.8.0.292.b10-1.el7_9                                            updates
    java-11-openjdk.i686                                                                    1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk.x86_64                                                                  1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-demo.i686                                                               1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-demo.x86_64                                                             1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-devel.i686                                                              1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-devel.x86_64                                                            1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-headless.i686                                                           1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-headless.x86_64                                                         1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-javadoc.i686                                                            1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-javadoc.x86_64                                                          1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-javadoc-zip.i686                                                        1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-javadoc-zip.x86_64                                                      1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-jmods.i686                                                              1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-jmods.x86_64                                                            1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-src.i686                                                                1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-src.x86_64                                                              1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-static-libs.i686                                                        1:11.0.11.0.9-1.el7_9                                              updates
    java-11-openjdk-static-libs.x86_64                                                      1:11.0.11.0.9-1.el7_9                                              updates
    java-atk-wrapper.i686                                                                   0.30.4-5.el7                                                       os     
    java-atk-wrapper.x86_64                                                                 0.30.4-5.el7                                                       os     
    java-dirq.noarch                                                                        1.8-1.el7                                                          epel   
    java-dirq-javadoc.noarch                                                                1.8-1.el7                                                          epel   
    java-latest-openjdk.x86_64                                                              1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-debug.x86_64                                                        1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-demo.x86_64                                                         1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-demo-debug.x86_64                                                   1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-demo-fastdebug.x86_64                                               1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-devel.x86_64                                                        1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-devel-debug.x86_64                                                  1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-devel-fastdebug.x86_64                                              1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-fastdebug.x86_64                                                    1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-headless.x86_64                                                     1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-headless-debug.x86_64                                               1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-headless-fastdebug.x86_64                                           1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-javadoc.x86_64                                                      1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-javadoc-zip.x86_64                                                  1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-jmods.x86_64                                                        1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-jmods-debug.x86_64                                                  1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-jmods-fastdebug.x86_64                                              1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-src.x86_64                                                          1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-src-debug.x86_64                                                    1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-src-fastdebug.x86_64                                                1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-static-libs.x86_64                                                  1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-static-libs-debug.x86_64                                            1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-latest-openjdk-static-libs-fastdebug.x86_64                                        1:16.0.1.0.9-1.rolling.el7                                         epel   
    java-oauth.noarch                                                                       20100601-13.el7                                                    epel   
    java-oauth-javadoc.noarch                                                               20100601-13.el7                                                    epel   
    java-runtime-decompiler.noarch                                                          3.0-2.el7                                                          epel   
    java-runtime-decompiler-javadoc.noarch                                                  3.0-2.el7                                                          epel   
    java_cup.noarch                                                                         1:0.11a-16.el7                                                     os     
    java_cup-javadoc.noarch                                                                 1:0.11a-16.el7                                                     os     
    java_cup-manual.noarch                                                                  1:0.11a-16.el7                                                     os     
    javacc.noarch                                                                           5.0-10.el7                                                         os     
    javacc-demo.noarch                                                                      5.0-10.el7                                                         os     
    javacc-javadoc.noarch                                                                   5.0-10.el7                                                         os     
    javacc-manual.noarch                                                                    5.0-10.el7                                                         os     
    javacc-maven-plugin.noarch                                                              2.6-17.el7                                                         os     
    javacc-maven-plugin-javadoc.noarch                                                      2.6-17.el7                                                         os     
    javamail.noarch                                                                         1.4.6-8.el7                                                        os     
    javamail-javadoc.noarch                                                                 1.4.6-8.el7                                                        os     
    javapackages-tools.noarch                                                               3.4.1-11.el7                                                       os     
    javaparser.noarch                                                                       1.0.11-3.el7                                                       epel   
    javaparser-javadoc.noarch                                                               1.0.11-3.el7                                                       epel   
    javassist.noarch                                                                        3.16.1-10.el7                                                      os     
    javassist-javadoc.noarch                                                                3.16.1-10.el7                                                      os     
    javastroke.x86_64                                                                       0.5.1-33.el7                                                       epel   
    javawriter.noarch                                                                       2.5.1-4.el7                                                        epel   
    javawriter-javadoc.noarch                                                               2.5.1-4.el7                                                        epel   

    2、查看Linux的系统位数

    getconf LONG_BIT

    结果为64位

    3、安装1.8的jdk

    yum install -y java-1.8.0-openjdk-devel.x86_64 --setopt=usr_w_check=false

    安装成功后,默认安装路径在/usr/lib/jvm/下边,

    注意:带-devel的安装的是jdk,而不带-devel的,实际上安装的是jre!

    /usr/lib/jvm目录中内容如下:

    total 4
    lrwxrwxrwx 1 root root   26 Nov 20 20:38 java -> /etc/alternatives/java_sdk
    lrwxrwxrwx 1 root root   32 Nov 20 20:38 java-1.8.0 -> /etc/alternatives/java_sdk_1.8.0
    lrwxrwxrwx 1 root root   40 Nov 20 20:38 java-1.8.0-openjdk -> /etc/alternatives/java_sdk_1.8.0_openjdk
    drwxr-xr-x 7 root root 4096 Nov 20 20:38 java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64
    lrwxrwxrwx 1 root root   34 Nov 20 20:38 java-openjdk -> /etc/alternatives/java_sdk_openjdk
    lrwxrwxrwx 1 root root   21 Nov 20 20:38 jre -> /etc/alternatives/jre
    lrwxrwxrwx 1 root root   27 Nov 20 20:38 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
    lrwxrwxrwx 1 root root   35 Nov 20 20:38 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk
    lrwxrwxrwx 1 root root   51 Nov 20 20:38 jre-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64 -> java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64/jre
    lrwxrwxrwx 1 root root   29 Nov 20 20:38 jre-openjdk -> /etc/alternatives/jre_openjdk

    4、查看jdk版本

    java -version

    结果

    openjdk version "1.8.0_312"
    OpenJDK Runtime Environment (build 1.8.0_312-b07)
    OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

    说明安装成功!

    5、查看java的安装路径

    which java

    结果为:/usr/bin/java

    ls -lrt /usr/bin/java

    6、设置环境变量

    vim /etc/profile

    在profile文件末尾新增如下内容:

    #set java environment
    JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64
    JRE_HOME=$JAVA_HOME/jre
    CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib 
    PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
    export JAVA_HOME JRE_HOME CLASS_PATH PATH

    二、卸载JDK

    1、使用rpm -qa | grep java | xargs rpm -e --nodeps 批量卸载所有带有Java的文件

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

    2、查看linux上面所有的jdk安装包

    rpm -qa | grep jdk

    结果如下

    copy-jdk-configs-3.3-10.el7_5.noarch
    java-1.8.0-openjdk-headless-1.8.0.312.b07-1.el7_9.x86_64
    java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64
    java-1.8.0-openjdk-devel-1.8.0.312.b07-1.el7_9.x86_64

    3、rpm -e --nodeps卸载对应的包

    rpm -e --nodeps copy-jdk-configs-3.3-10.el7_5.noarch
    rpm -e --nodeps java-1.8.0-openjdk-headless-1.8.0.312.b07-1.el7_9.x86_64
    rpm -e --nodeps java-1.8.0-openjdk-1.8.0.312.b07-1.el7_9.x86_64
    rpm -e --nodeps java-1.8.0-openjdk-devel-1.8.0.312.b07-1.el7_9.x86_64

    如果删除不了,使用下面的命令

    rpm -ev python-javapackages-3.4.1-11.el7.noarch --nodeps
    rpm -ev javapackages-tools-3.4.1-11.el7.noarch --nodeps
    rpm -ev tzdata-java-2021e-1.el7.noarch --nodeps

    4、删除残留jdk文件

    find / -name jdk

    5、卸载jdk

    rm -rf JDK地址

    6、vim命令编辑文件profile

     vim /etc/profile

    删除下面的配置

    export JAVA_HOME=/root/jenkins/data/jdk1.8.0_202
    export CLASSPATH=$:CLASSPATH:$JAVA_HOME/lib/
    export PATH=$PATH:$JAVA_HOME/bin

    删除配置的环境变量,至此JDK卸载完毕

    执行下面的命令使配置生效

    source /etc/profile

    7、检查下自带的jdk

    rpm -qa |grep java
    rpm -qa |grep jdk
    rpm -qa |grep gcj

    结果

    python-javapackages-3.4.1-11.el7.noarch
    tzdata-java-2021e-1.el7.noarch
    javapackages-tools-3.4.1-11.el7.noarch
  • 相关阅读:
    [Codechef Coders' Legacy 2018 CLSUMG]Sum of Primes
    [HDU4630]No Pain No Game
    [Luogu4329][COCI2006]Bond
    [数论]Gcd/ExGcd欧几里得学习笔记
    [数论]线性基学习笔记
    [Luogu5190][COCI2010]PROGRAM
    IIS7 HTTPS 绑定主机头,嘿嘿,转
    React
    ios
    iOS10 权限配置
  • 原文地址:https://www.cnblogs.com/zwh0910/p/15582330.html
Copyright © 2020-2023  润新知