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的虚拟机)是广泛 ...
随机推荐
- UIView的transform
iOS开发UIView的transform属性详解 本文主要是详解iOS开发UIView的transform属性 CGAffineTransform实际上是一个矩阵 | a, b, 0 | | c ...
- OpenCV 学习笔记 02 处理文件、摄像头和图形用户界面
在处理文件前需要引入OpenCV库,同时也引入unmpy库 import cv2 import numpy as np 1 基本的读写操作 1.1 图像文件的读写操作 1.1.1 图像文件的读取操作 ...
- MongoDB学习笔记(11) --- 聚合
MongoDB中聚合(aggregate)主要用于处理数据(诸如统计平均值,求和等),并返回计算后的数据结果.有点类似sql语句中的 count(*) aggregate() 方法 MongoDB中聚 ...
- c# 笔试题及参考答案大全
http://blog.csdn.net/smileberry1/article/details/3958670
- OPENSSL编程起步
原文链接: http://blog.csdn.net/itmes/article/details/7711076 WINDOWS平台下OPENSSL的编译和安装使用 OPENSSL是开放源代码的,可以 ...
- 人民币金额转化汉字的java写法
最近看到一个把一个浮点数转化为汉字人民币的小题,感觉很有意思就去用java实现了一下,没想到没有想得那么简单,在网上搜了一下也不近人意,经过几次修改后,现在实现了,现在分享一下. 一.当输入一个浮点数 ...
- django -- 为model 指定数据库名
一.为model指定数据库名: django自己实现的ORM中.如果要指定一个model的表名是通过Meta类来实现的. from django.db import models # Create y ...
- Linux磁盘IO监控[zz]
磁盘 I/O 监控是 Unix/Linux 系统管理中一个非常重要的组成部分.它可以监控吞吐量.每秒 I/O 数.磁盘利用率.服务时间等信息,并且在发现异常时,发送告警信息给系统管理员,便于系统管理员 ...
- shell编程入门(一)
运行Linux程序有三种方法: (1).使文件具有可执行权限,直接运行文件. (2).直接调用命令解释器执行程序(Linux shell是一种解释型语言). (3).使用source执行文件 第一种: ...
- mysql分享一:运维角度浅谈MySQL数据库优化
转于:http://lizhenliang.blog.51cto.com/7876557/1657465 1.数据库表设计要合理避免慢查询.低效的查询语句.没有适当建立索引.数据库堵塞(死锁)等 2. ...