Ubuntu安装JDK

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.

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容