How to install the JDK on Ubuntu Linux

I am trying to install the Java Development Kit (JDK) on Ubuntu Linux distribution, but I am unable to install it.

What are the steps to install it on Ubuntu?


Referring to Ask Ubuntu question How to set JAVA_HOME for OpenJDK?,

How to install "Open JDK" (Java developement kit) in Ubuntu (Linux)?

  • Open Terminal from Application Dash or press Ctrl+Alt+T

  • Update repository:

    sudo add-apt-repository ppa:openjdk-r/ppa
    sudo apt-get update
    
  • Run the following command in Terminal:

    sudo apt-get install openjdk-8-jdk
    sudo apt-get install openjdk-8-source #this is optional, the jdk source code
    
  • Type commandline as below...

    apt-cache search jdk
    

    (Note: openjdk-8-jdk is symbolically used here. You can choose the JDK version as per your requirement.)

  • For "JAVA_HOME" (Environment Variable) type command as shown below, in "Terminal" using your installation path...

    export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
    

    (Note: "/usr/lib/jvm/java-8-openjdk" is symbolically used here just for demostration. You should use your path as per your installation.)

  • For "PATH" (Environment Variable) type command as shown below, in "Terminal" using your installation path...

    export PATH=$PATH:/usr/lib/jvm/java-8-openjdk/bin
    

    (Note: "/usr/lib/jvm/java-8-openjdk" is symbolically used here just for demostration. You should use your path as per your installation.)

  • Check for "open jdk" installation, just type command in "Terminal" as shown below

    javac -version
    

  • sudo add-apt-repository ppa:webupd8team/java
    sudo apt-get update
    sudo apt-get install oracle-java7-installer
    

    You can install Oracle's JDK 1.7 fairly easily too; as an example this is how to install JDK 1.7.0_13;

  • Download the JDK from Oracle's site. The download to the newest version is always linked from http://java.oracle.com.
  • As root, do;

    cd /usr/local
    tar xzf <the file you just downloaded>
    

    As your normal user, add or change these two lines in your ~/.profile to point to the installation;

    export JAVA_HOME=/usr/local/jdk1.7.0_13
    export PATH=$PATH:$JAVA_HOME/bin
    

    If it's an update, you may also want to remove the old java installation directory in /usr/local .

    Log out and in again (or do . ~/.profile ), and everything should just work.

    The downside with Oracle's JDK is that it won't update with the rest of your system like OpenJDK will, so I'd mostly consider it if you're running programs that require it.

    链接地址: http://www.djcxy.com/p/54764.html

    上一篇: Python的unicode错误取决于我提供的路径?

    下一篇: 如何在Ubuntu Linux上安装JDK