zoukankan      html  css  js  c++  java
  • linux 上使用yum 安装openjdk1.8

     

    1. 使用yum查找jdk: yum search java|grep jdk

      # 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
      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 accessibility connector
      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 with full debug on
      java-1.8.0-openjdk-demo.i686 : OpenJDK Demos
      java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos
      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 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
      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 with
      java-1.8.0-openjdk-headless.i686 : OpenJDK Runtime Environment
      java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment
      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 API Documentation
      java-1.8.0-openjdk-javadoc-debug.noarch : OpenJDK API Documentation for packages
      java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK API Documentation compressed in
      java-1.8.0-openjdk-javadoc-zip-debug.noarch : OpenJDK API Documentation
      java-1.8.0-openjdk-src.i686 : OpenJDK Source Bundle
      java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle
      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 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
    2. 执行安装命令:yum install java-1.8.0-openjdk

      安装成功后,默认安装路径在/usr/lib/jvm/下边,
      如/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el6_9.x86_64

      查看安装路径(如下所示):
      which java
      ls -lrt /usr/bin/java

      [root@preproduct1 ~]# which java
      /usr/bin/java
      [root@preproduct1 ~]# echo $JAVA_HOME
      /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
      [root@preproduct1 ~]# ls -lrt /usr/bin/java
      lrwxrwxrwx 1 root root 22 Feb 13 10:40 /usr/bin/java -> /etc/alternatives/java
      [root@preproduct1 ~]# ls -lrt /etc/alternatives/java
      lrwxrwxrwx 1 root root 73 Feb 13 10:40 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre/bin/java
      [root@preproduct1 ~]# cd /usr/lib/jvm
      [root@preproduct1 /usr/lib/jvm]# ll
      total 4
      lrwxrwxrwx 1 root root   26 Feb 13 10:44 java -> /etc/alternatives/java_sdk
      lrwxrwxrwx 1 root root   32 Feb 13 10:44 java-1.8.0 -> /etc/alternatives/java_sdk_1.8.0
      lrwxrwxrwx 1 root root   40 Feb 13 10:44 java-1.8.0-openjdk -> /etc/alternatives/java_sdk_1.8.0_openjdk
      drwxr-xr-x 7 root root 4096 Feb 13 10:44 java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64
      lrwxrwxrwx 1 root root   34 Feb 13 10:44 java-openjdk -> /etc/alternatives/java_sdk_openjdk
      lrwxrwxrwx 1 root root   21 Feb 13 10:40 jre -> /etc/alternatives/jre
      lrwxrwxrwx 1 root root   27 Feb 13 10:40 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
      lrwxrwxrwx 1 root root   35 Feb 13 10:40 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk
      lrwxrwxrwx 1 root root   51 Feb 13 10:40 jre-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64 -> java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/jre
      lrwxrwxrwx 1 root root   29 Feb 13 10:40 jre-openjdk -> /etc/alternatives/jre_openjdk
    3. 验证java是否安装成功

      • 查看java版本:java -version

        # java -version
        openjdk version "1.8.0_191"
        OpenJDK Runtime Environment (build 1.8.0_191-b12)
        OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
      • 查看java是否可用:javac

        # javac
        -bash: javac: command not found

        错误原因:默认安装完只有运行环境,java安装目录下只有jre文件夹

    4. 安装开发环境yum install java-1.8.0-openjdk-devel.x86_64
      安装完可看到java安装目录下出现bin、lib等文件夹:

      [root@preproduct1 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64]# l
      total 20
      drwxr-xr-x 2 root root 4096 Feb 13 10:44 bin
      drwxr-xr-x 3 root root 4096 Feb 13 10:44 include
      drwxr-xr-x 4 root root 4096 Feb 13 10:40 jre
      drwxr-xr-x 3 root root 4096 Feb 13 10:44 lib
      drwxr-xr-x 2 root root 4096 Feb 13 10:44 tapset

      再次输入javac说明安装成功

      # javac
      Usage: javac <options> <source files>
      where possible options include:
        -g                         Generate all debugging info
        -g:none                    Generate no debugging info
        -g:{lines,vars,source}     Generate only some debugging info
        -nowarn                    Generate no warnings
        -verbose                   Output messages about what the compiler is doing
        -deprecation               Output source locations where deprecated APIs are use
        -classpath <path>          Specify where to find user class files and annotationocessors
        -cp <path>                 Specify where to find user class files and annotationocessors
        -sourcepath <path>         Specify where to find input source files
        -bootclasspath <path>      Override location of bootstrap class files
        -extdirs <dirs>            Override location of installed extensions
        -endorseddirs <dirs>       Override location of endorsed standards path
        -proc:{none,only}          Control whether annotation processing and/or compilat is done.
        -processor <class1>[,<class2>,<class3>...] Names of the annotation processors ton; bypasses default discovery process
        -processorpath <path>      Specify where to find annotation processors
        -parameters                Generate metadata for reflection on method parameters
        -d <directory>             Specify where to place generated class files
        -s <directory>             Specify where to place generated source files
        -h <directory>             Specify where to place generated native header files
        -implicit:{none,class}     Specify whether or not to generate class files for imcitly referenced files
        -encoding <encoding>       Specify character encoding used by source files
        -source <release>          Provide source compatibility with specified release
        -target <release>          Generate class files for specific VM version
        -profile <profile>         Check that API used is available in the specified proe
        -version                   Version information
        -help                      Print a synopsis of standard options
        -Akey[=value]              Options to pass to annotation processors
        -X                         Print a synopsis of nonstandard options
        -J<flag>                   Pass <flag> directly to the runtime system
        -Werror                    Terminate compilation if warnings occur
        @<filename>                Read options and filenames from file
    5. 设置环境变量
      修改/etc/profile文件:vi /etc/profile
      在profile文件末尾新增如下内容:

      #set java environment
         JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.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

      使环境变量生效:source /etc/profile

      [root@preproduct1 /usr/lib/jvm]# cd /usr/lib/jvm
      [root@preproduct1 /usr/lib/jvm]# cd java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64/
      [root@preproduct1 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64]# source /etc/profile
      [root@preproduct1 /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64]# echo $JAVA_HOME
      /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.el7_6.x86_64

    至此jdk安装成功

  • 相关阅读:
    DGA域名可以是色情网站域名
    使用cloudflare加速你的网站隐藏你的网站IP
    167. Two Sum II
    leetcode 563. Binary Tree Tilt
    python 多线程
    leetcode 404. Sum of Left Leaves
    leetcode 100. Same Tree
    leetcode 383. Ransom Note
    leetcode 122. Best Time to Buy and Sell Stock II
    天津Uber优步司机奖励政策(12月28日到12月29日)
  • 原文地址:https://www.cnblogs.com/yaun1498078591/p/10368884.html
Copyright © 2011-2022 走看看