Ubuntu安装JDK

作者: 清白的少年 | 来源:发表于2018-04-10 20:42 被阅读0次

    Installing the Default JRE/JDK
    1,$sudo apt-get update
    2,$sudo apt-get install default-jre
    3,$sudo apt-get install default-jdk

    Installing the Oracle JDK
    1,$sudo add-apt-repository ppa:webupd8team/java
    2,$sudo apt-get update
    Oracle JDK 6 or 7 or 8 or 9
    $sudo apt-get install oracle-java6-installer
    $sudo apt-get install oracle-java7-installer

    Managing Java
    $sudo update-alternatives --config java

    You can now choose the number to use as a default. This can also be done for other Java commands, such as the compiler (javac), the documentation generator (javadoc), the JAR signing tool (jarsigner), and more. You can use the following command, filling in the command you want to customize.

    $sudo update-alternatives --config command
    

    Setting the JAVA_HOME Environment Variable
    Many programs, such as Java servers, use the JAVA_HOME environment variable to determine the Java installation location. To set this environment variable, we will first need to find out where Java is installed. You can do this by executing the same command as in the previous section:

    $sudo update-alternatives --config java
    

    Copy the path from your preferred installation and then open /etc/environment using nano or your favorite text editor.

    $ sudo nano /etc/environment

    At the end of this file, add the following line, making sure to replace the highlighted path with your own copied path.
    /etc/environment

    JAVA_HOME="/usr/lib/jvm/java-8-oracle"

    Save and exit the file, and reload it.

    $source /etc/environment
    

    You can now test whether the environment variable has been set by executing the following command:

    $echo $JAVA_HOME
    

    This will return the path you just set.

    相关文章

      网友评论

        本文标题:Ubuntu安装JDK

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