美文网首页
Centos下JDK的三种安装方法

Centos下JDK的三种安装方法

作者: 丁庆华 | 来源:发表于2019-08-17 21:38 被阅读0次

    方法一:手动解压JDK的压缩包,然后设置环境变量

    1. 在/usr/目录下创建java目录
    [root@localhost ~]# mkdir /usr/java
    [root@localhost ~]# cd /usr/java
    

    2.下载jdk,然后解压并copy到/opt/java(任意目录即可)

    [root@localhost soft]# tar -xzvf jdk-8u221-linux-x64.tar.gz 
    [root@localhost soft]# mkdir /opt/java
    [root@localhost soft]# cp -r jdk1.8.0_221/ /opt/java/
    
    1. 设置环境变量,修改/etc/profile,在文件的底部添加如下内容
    # set java environment
    JAVA_HOME=/opt/java/jdk1.8.0_221
    JRE_HOME=/opt/java/jdk1.8.0_221/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
    

    让修改生效:

    [root@localhost java]# source /etc/profile
    

    4.验证JDK有效性

    [root@localhost java]# clear
    [root@localhost java]# java -version
    java version "1.8.0_221"
    Java(TM) SE Runtime Environment (build 1.8.0_221-b11)
    Java HotSpot(TM) 64-Bit Server VM (build 25.221-b11, mixed mode)
    [root@localhost java]# 
    

    方法二:用yum安装JDK

    1.查看yum库中都有哪些jdk版本(暂时只发现了openjdk)

    [root@localhost java]# yum search java|grep jdk
    ldapjdk-javadoc.noarch : Javadoc for ldapjdk
    java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
    java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
    java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
    java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
    java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
    java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
    java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
    java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
    java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
    java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
    java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
    java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
    java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment
    java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment 8
    java-1.8.0-openjdk-accessibility.i686 : OpenJDK accessibility connector
    java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
    java-1.8.0-openjdk-accessibility-debug.i686 : OpenJDK accessibility connector
    java-1.8.0-openjdk-accessibility-debug.x86_64 : OpenJDK 8 accessibility
    java-1.8.0-openjdk-debug.i686 : OpenJDK Runtime Environment with full debug on
    java-1.8.0-openjdk-debug.x86_64 : OpenJDK Runtime Environment 8 with full debug
    java-1.8.0-openjdk-demo.i686 : OpenJDK Demos
    java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos 8
    java-1.8.0-openjdk-demo-debug.i686 : OpenJDK Demos with full debug on
    java-1.8.0-openjdk-demo-debug.x86_64 : OpenJDK Demos 8 with full debug on
    java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment
    java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment 8
    java-1.8.0-openjdk-devel-debug.i686 : OpenJDK Development Environment with full
    java-1.8.0-openjdk-devel-debug.x86_64 : OpenJDK Development Environment 8 with
    java-1.8.0-openjdk-headless.i686 : OpenJDK Runtime Environment
    java-1.8.0-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 8
    java-1.8.0-openjdk-headless-debug.i686 : OpenJDK Runtime Environment with full
    java-1.8.0-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full
    java-1.8.0-openjdk-javadoc.noarch : OpenJDK 8 API documentation
    java-1.8.0-openjdk-javadoc-debug.noarch : OpenJDK 8 API documentation for
    java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK 8 API documentation compressed
    java-1.8.0-openjdk-javadoc-zip-debug.noarch : OpenJDK 8 API documentation
    java-1.8.0-openjdk-src.i686 : OpenJDK Source Bundle
    java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle 8
    java-1.8.0-openjdk-src-debug.i686 : OpenJDK Source Bundle for packages with
    java-1.8.0-openjdk-src-debug.x86_64 : OpenJDK Source Bundle 8 for packages with
    java-11-openjdk.i686 : OpenJDK Runtime Environment 11
    java-11-openjdk.x86_64 : OpenJDK Runtime Environment 11
    java-11-openjdk-debug.i686 : OpenJDK Runtime Environment 11 with full debug on
    java-11-openjdk-debug.x86_64 : OpenJDK Runtime Environment 11 with full debug on
    java-11-openjdk-demo.i686 : OpenJDK Demos 11
    java-11-openjdk-demo.x86_64 : OpenJDK Demos 11
    java-11-openjdk-demo-debug.i686 : OpenJDK Demos 11 with full debug on
    java-11-openjdk-demo-debug.x86_64 : OpenJDK Demos 11 with full debug on
    java-11-openjdk-devel.i686 : OpenJDK Development Environment 11
    java-11-openjdk-devel.x86_64 : OpenJDK Development Environment 11
    java-11-openjdk-devel-debug.i686 : OpenJDK Development Environment 11 with full
    java-11-openjdk-devel-debug.x86_64 : OpenJDK Development Environment 11 with
    java-11-openjdk-headless.i686 : OpenJDK Headless Runtime Environment 11
    java-11-openjdk-headless.x86_64 : OpenJDK Headless Runtime Environment 11
    java-11-openjdk-headless-debug.i686 : OpenJDK Runtime Environment with full
    java-11-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full
    java-11-openjdk-javadoc.i686 : OpenJDK 11 API documentation
    java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation
    java-11-openjdk-javadoc-debug.i686 : OpenJDK 11 API documentation for packages
    java-11-openjdk-javadoc-debug.x86_64 : OpenJDK 11 API documentation for packages
    java-11-openjdk-javadoc-zip.i686 : OpenJDK 11 API documentation compressed in
    java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in
    java-11-openjdk-javadoc-zip-debug.i686 : OpenJDK 11 API documentation compressed
    java-11-openjdk-javadoc-zip-debug.x86_64 : OpenJDK 11 API documentation
    java-11-openjdk-jmods.i686 : JMods for OpenJDK 11
    java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11
    java-11-openjdk-jmods-debug.i686 : JMods for OpenJDK 11 with full debug on
    java-11-openjdk-jmods-debug.x86_64 : JMods for OpenJDK 11 with full debug on
    java-11-openjdk-src.i686 : OpenJDK Source Bundle 11
    java-11-openjdk-src.x86_64 : OpenJDK Source Bundle 11
    java-11-openjdk-src-debug.i686 : OpenJDK Source Bundle for packages with debug
    java-11-openjdk-src-debug.x86_64 : OpenJDK Source Bundle 11 for packages with
    ldapjdk.noarch : The Mozilla LDAP Java SDK
    [root@localhost java]# 
    

    2.选择版本,进行安装,此处选择安装java-1.8.0-openjdk.x86_64

    yum install java-1.8.0-openjdk.x86_64
    

    //安装完之后,默认的安装目录是在: /usr/lib/jvm。经验证,该版本在安装后自动设置 环境变量

    3.验证(同上一方法)

    说明:采用yum方式安装不需要设置环境变量

    方法三:用rpm安装JDK

    1.下载rpm安装文件
    同于现在下载都需要用账号登录,下载步骤略,大家可百度。

    2.使用rpm命令安装

    [root@localhost soft]# rpm -ivh jdk-8u221-linux-x64.rpm
    

    4.验证(同上一方法)

    注:和yum安装类似,不用设置环境变量就可以运行java命令。rpm安装方式默认会把jdk安装到/usr/java/jdk1.8.0_221-amd64,然后通过三层链接,链接到/usr/bin,具体链接如下:

    [root@localhost alternatives]# cd /usr/java/
    [root@localhost java]# ll
    total 4
    lrwxrwxrwx. 1 root root   16 Aug 17 21:26 default -> /usr/java/latest
    drwxr-xr-x. 8 root root 4096 Aug 17 21:26 jdk1.8.0_221-amd64
    lrwxrwxrwx. 1 root root   28 Aug 17 21:26 latest -> /usr/java/jdk1.8.0_221-amd64
    [root@localhost java]# 
    [root@localhost java]# cd /bin/
    [root@localhost bin]# ll |grep java
    lrwxrwxrwx. 1 root root        22 Aug 17 21:26 java -> /etc/alternatives/java
    lrwxrwxrwx. 1 root root        23 Aug 17 21:26 javac -> /etc/alternatives/javac
    lrwxrwxrwx. 1 root root        25 Aug 17 21:26 javadoc -> /etc/alternatives/javadoc
    lrwxrwxrwx. 1 root root        32 Aug 17 21:26 javafxpackager -> /etc/alternatives/javafxpackager
    lrwxrwxrwx. 1 root root        23 Aug 17 21:26 javah -> /etc/alternatives/javah
    lrwxrwxrwx. 1 root root        23 Aug 17 21:26 javap -> /etc/alternatives/javap
    lrwxrwxrwx. 1 root root        30 Aug 17 21:26 javapackager -> /etc/alternatives/javapackager
    lrwxrwxrwx. 1 root root        30 Aug 17 21:26 java-rmi.cgi -> /etc/alternatives/java-rmi.cgi
    lrwxrwxrwx. 1 root root        24 Aug 17 21:26 javaws -> /etc/alternatives/javaws
    [root@localhost bin]# 
    

    相关文章

      网友评论

          本文标题:Centos下JDK的三种安装方法

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