美文网首页
ubuntu 16.04 安装jdk

ubuntu 16.04 安装jdk

作者: sakura_L | 来源:发表于2018-01-19 15:47 被阅读63次

    http://topspeedsnail.com/ubuntu16-install-java-jdk/

    <article class="post" style="box-sizing: border-box; margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; display: block;">

    Ubuntu 16.04安装Java JDK

    Java JDK有两个版本,一个开源版本Openjdk,还有一个oracle官方版本jdk。下面记录在Ubuntu 16.04上安装Java JDK的步骤。

    安装openjdk

    更新软件包列表:

    <figure class="highlight" style="box-sizing: border-box; margin: 20px 0px; padding: 7px 7px 7px 10px; border: 1px solid rgb(221, 221, 221); font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; display: block; background-color: rgb(239, 239, 239); box-shadow: rgba(0, 0, 0, 0.0980392) 3px 3px; overflow: scroll;">

    $ sudo apt-get update
    

    </figure>

    安装openjdk-8-jdk:

    <figure class="highlight" style="box-sizing: border-box; margin: 20px 0px; padding: 7px 7px 7px 10px; border: 1px solid rgb(221, 221, 221); font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; display: block; background-color: rgb(239, 239, 239); box-shadow: rgba(0, 0, 0, 0.0980392) 3px 3px; overflow: scroll;">

    $ sudo apt-get install openjdk-8-jdk
    

    </figure>

    查看java版本:

    <figure class="highlight" style="box-sizing: border-box; margin: 20px 0px; padding: 7px 7px 7px 10px; border: 1px solid rgb(221, 221, 221); font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; display: block; background-color: rgb(239, 239, 239); box-shadow: rgba(0, 0, 0, 0.0980392) 3px 3px; overflow: scroll;">

    $ java -version
    

    </figure>

    java Ubuntu 16.04

    安装oracle Java JDK

    首先,安装依赖包:

    <figure class="highlight" style="box-sizing: border-box; margin: 20px 0px; padding: 7px 7px 7px 10px; border: 1px solid rgb(221, 221, 221); font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; display: block; background-color: rgb(239, 239, 239); box-shadow: rgba(0, 0, 0, 0.0980392) 3px 3px; overflow: scroll;">

    $ sudo apt-get install python-software-properties
    

    </figure>

    添加仓库源:

    <figure class="highlight" style="box-sizing: border-box; margin: 20px 0px; padding: 7px 7px 7px 10px; border: 1px solid rgb(221, 221, 221); font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; display: block; background-color: rgb(239, 239, 239); box-shadow: rgba(0, 0, 0, 0.0980392) 3px 3px; overflow: scroll;">

    $ sudo add-apt-repository ppa:webupd8team/java
    

    </figure>

    更新软件包列表:

    <figure class="highlight" style="box-sizing: border-box; margin: 20px 0px; padding: 7px 7px 7px 10px; border: 1px solid rgb(221, 221, 221); font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; display: block; background-color: rgb(239, 239, 239); box-shadow: rgba(0, 0, 0, 0.0980392) 3px 3px; overflow: scroll;">

    $ sudo apt-get update
    

    </figure>

    安装java JDK:

    <figure class="highlight" style="box-sizing: border-box; margin: 20px 0px; padding: 7px 7px 7px 10px; border: 1px solid rgb(221, 221, 221); font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; display: block; background-color: rgb(239, 239, 239); box-shadow: rgba(0, 0, 0, 0.0980392) 3px 3px; overflow: scroll;">

    $ sudo apt-get install oracle-java8-installer
    

    </figure>

    安装过程中需要接受协议:

    java Ubuntu 16.04

    查看java版本:

    <figure class="highlight" style="box-sizing: border-box; margin: 20px 0px; padding: 7px 7px 7px 10px; border: 1px solid rgb(221, 221, 221); font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; display: block; background-color: rgb(239, 239, 239); box-shadow: rgba(0, 0, 0, 0.0980392) 3px 3px; overflow: scroll;">

    $ java -version
    

    </figure>

    java Ubuntu 16.04

    如果你同时安装了以上两个版本,你可以自由的在这两个版本之间切换。执行:

    <figure class="highlight" style="box-sizing: border-box; margin: 20px 0px; padding: 7px 7px 7px 10px; border: 1px solid rgb(221, 221, 221); font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; display: block; background-color: rgb(239, 239, 239); box-shadow: rgba(0, 0, 0, 0.0980392) 3px 3px; overflow: scroll;">

    $ sudo update-alternatives --config java
    

    </figure>

    java Ubuntu 16.04

    前面带星号的是当前正在使用的java版本,键入编号选择使用哪个版本。

    编辑/etc/profile,在文件尾添加java环境变量:

    <figure class="highlight" style="box-sizing: border-box; margin: 20px 0px; padding: 7px 7px 7px 10px; border: 1px solid rgb(221, 221, 221); font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; vertical-align: baseline; display: block; background-color: rgb(239, 239, 239); box-shadow: rgba(0, 0, 0, 0.0980392) 3px 3px; overflow: scroll;">

    $ sudo vim /etc/profile
    

    </figure>

    # 如果使用oracle java
    export JAVA_HOME="/usr/lib/jvm/java-8-oracle/jre/bin"
    
    # 如果使用openjdk
    export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin"
    
    

    OK,在Ubuntu 16.04上安装java完成。

    相关文章

      网友评论

          本文标题:ubuntu 16.04 安装jdk

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