How To Install Java with Apt-Get on Ubuntu 16.04
Introduction
Java and the JVM (Java's virtual machine) are widely used and required for many kinds of software. This article will guide you through the process of installing and managing different versions of Java using apt-get.
Prerequisites
To follow this tutorial, you will need:
One Ubuntu 16.04 server.
A sudo non-root user, which you can set up by following the Ubuntu 16.04 initial server setup guide.
Installing the Default JRE/JDK
The easiest option for installing Java is using the version packaged with Ubuntu. Specifically, this will install OpenJDK 8, the latest and recommended version.
First, update the package index.
- sudo apt-get update
Next, install Java. Specifically, this command will install the Java Runtime Environment (JRE).
- sudo apt-get install default-jre
There is another default Java installation called the JDK (Java Development Kit). The JDK is usually only needed if you are going to compile Java programs or if the software that will use Java specifically requires it.
The JDK does contain the JRE, so there are no disadvantages if you install the JDK instead of the JRE, except for the larger file size.
You can install the JDK with the following command:
- sudo apt-get install default-jdk
Installing the Oracle JDK
If you want to install the Oracle JDK, which is the official version distributed by Oracle, you will need to follow a few more steps.
First, add Oracle's PPA, then update your package repository.
- sudo add-apt-repository ppa:webupd8team/java
- sudo apt-get update
Then, depending on the version you want to install, execute one of the following commands:
Oracle JDK 8
This is the latest stable version of Java at time of writing, and the recommended version to install. You can do so using the following command:
- sudo apt-get install oracle-java8-installer
Oracle JDK 9
This is a developer preview and the general release is scheduled for March 2017. It's not recommended that you use this version because there may still be security issues and bugs. There is more information about Java 9 on the official JDK 9 website.
To install JDK 9, use the following command:
- sudo apt-get install oracle-java9-installer
Managing Java
There can be multiple Java installations on one server. You can configure which version is the default for use in the command line by using update-alternatives, which manages which symbolic links are used for different commands.
- sudo update-alternatives --config java
The output will look something like the following. In this case, this is what the output will look like with all Java versions mentioned above installed.
There are 5 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 auto mode
1 /usr/lib/jvm/java-6-oracle/jre/bin/java 1 manual mode
2 /usr/lib/jvm/java-7-oracle/jre/bin/java 2 manual mode
3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
4 /usr/lib/jvm/java-8-oracle/jre/bin/java 3 manual mode
5 /usr/lib/jvm/java-9-oracle/bin/java 4 manual mode
Press <enter> to keep the current choice[*], or type selection number:
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.
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.
Conclusion
You have now installed Java and know how to manage different versions of it. You can now install software which runs on Java, such as Tomcat, Jetty, Glassfish, Cassandra, or Jenkins.
How To Install Java with Apt-Get on Ubuntu 16.04的更多相关文章
- Ubuntu 16.04安装ROS Kinetic详细教程 | Tutorial to Install and Configure ROS Kinetic on Ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/e2780b93/,欢迎阅读! Tutorial to Install and Configure ROS Kinetic on U ...
- Install and Configure Apache Kafka on Ubuntu 16.04
https://devops.profitbricks.com/tutorials/install-and-configure-apache-kafka-on-ubuntu-1604-1/ by hi ...
- Install .NET Core Runtime on Linux Ubuntu 16.04 x64
原文链接https://www.microsoft.com/net/download/linux-package-manager/ubuntu16-04/runtime-current nstall ...
- ubuntu 16.04源码编译和配置caffe详细教程 | Install and Configure Caffe on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/b90033a9/,欢迎阅读! Install and Configure Caffe on ubuntu 16.04 Series ...
- Ubuntu 16.04 安装 Wireshark分析tcpdump的pcap包——sudo apt install wireshark-qt
tcpdump 的抓包保存到文件的命令参数是-w xxx.cap 抓eth1的包 tcpdump -i eth1 -w /tmp/xxx.cap 抓 192.168.1.123的包 tc ...
- Ubuntu 16.04配置OpenCV 3.1.0 for Java
我们都知道,OpenCV是基于C++的开源计算机视觉库,但是从2.4.4版本开始提供了Java绑定,也就是说,我们也可以使用Java来开发基于OpenCV的计算机视觉应用.目前,最新的版本是3.1.0 ...
- How to Install LibreOffice 6.0 on Ubuntu 16.04 LTS +
1. Add the LibreOffice 6.0 PPA The LibreOffice Fresh PPA is maintained by LibreOffice. It provides l ...
- digitalocean --- How To Install Apache Tomcat 8 on Ubuntu 16.04
https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04 Intr ...
- 在Ubuntu 16.04如何安装Java使用apt-get的
转自:https://www.howtoing.com/how-to-install-java-with-apt-get-on-ubuntu-16-04/ 的Java和JVM(Java的虚拟机)是广泛 ...
随机推荐
- Event事件的兼容性(转)
window.event问题问题说明:window.event 只能在IE下运行,而不能在Firefox下运行,这是因为Firefox的event只能在事件发生的现场使用.解决方法:在事件发生的函数上 ...
- XML 特殊字符处理
在XML中,有一些符号作为XML 的标记符号,一些特定情况下,属性值必须带有这些特殊符号. 下面主要是讲解一些常用的特殊符号的处理 例一: 双引号的使用. 双引号作为XML 属性值的开始结束符号,因此 ...
- ELK 5.X版本遇到的坑
一.Kafka ->logstash ->elasticsearch logstash 5.X以上版本不兼容5.x以下版本,因此在升级logstash时会遇到很多坑.首先是配置的变化 ...
- cors的实现原理
如何辨认一个请求的源domain? 如何发送和处理cors请求? 优势 和 弱点 cookie 和 伪装 1. http://www.staticapps.org/articles/cross-dom ...
- dig 命令
dig命令是常用的域名查询工具,可以用来测试域名系统工作是否正常. 语法 dig(选项)(参数) 选项 @<服务器地址>:指定进行域名解析的域名服务器: -b<ip地址>:当主 ...
- ldd命令
ldd命令用于判断某个可执行的 binary 档案含有什么动态函式库. 参数说明: --version 打印ldd的版本号 -v --verbose 打印所有信息,例如包括符号的版本信息 -d --d ...
- Github emoji 表情包大全
传送门:https://www.jianshu.com/p/72a4214764e4 https://www.webpagefx.com/tools/emoji-cheat-sheet/
- Knockout: radio选项切换引发click事件的一点总结
1.场景:如下图,当选择定期存款时,输入框右边出现红色的必输项星号,当选择活期存款时,不再出现该星号. 2.思路一:不使用knockout,直接用click事件,就可以实现这个需求,代码如下: < ...
- 在ubuntu14系统中将redis-server设置为开机启动项
1.redis安装完成后(我装的是redis-3.0.7),修改配置文件redis.conf,修改的项目如下 注意:以下内容都是在root用户下进行操作的 gedit redis.conf打开文件进行 ...
- Android调试桥-Android Debug Birdge详解
原文:http://android.eoe.cn/topic/summary Android调试桥-Android Debug Birdge Android调试桥(adb)是一个多功能的命令行功具,它 ...