How To Install Java with Apt-Get on Ubuntu 16.04

Koen Vlaswinkel

Subscribe

Share

29

How To Install Java with Apt-Get on Ubuntu 16.04

PostedApril 23, 2016 1.1mviews JAVA UBUNTU 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:

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.

Output

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.

/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.

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.

时间: 2024-10-12 08:34:03

How To Install Java with Apt-Get on Ubuntu 16.04的相关文章

Install and Configure Apache Kafka on Ubuntu 16.04

https://devops.profitbricks.com/tutorials/install-and-configure-apache-kafka-on-ubuntu-1604-1/ by hitjethvaon Oct 03, 2016 Intermediate Table of Contents Introduction Features Requirements Getting Started Installing Java Install ZooKeeper Install and

Install .NET Core Runtime on Linux Ubuntu 16.04 x64

原文链接https://www.microsoft.com/net/download/linux-package-manager/ubuntu16-04/runtime-current nstall .NET Core Runtime on Linux Ubuntu 16.04 x64 Not sure where to start? See Get started with .NET in 10 minutes. Linux Distribution                  RHEL

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 Part 1: Install and Configure Caffe on windows 10 Part 2: Install and Configure Caffe on ubuntu 16.04 Guide requirements: NVIDIA driver 396.54 CUDA 8

Ubuntu 16.04 LTS软件包管理基本操作使用APT简化命令行下面我们列出 Ubuntu 16.04 LTS 中使用 ATP 命令与老版本 Ubuntu 中软件包管理的用法对比: Ubuntu 16.04 LTS 老版本Ubuntu apt install 包名 替代 apt-get install 包名 apt remove 包名 替代 apt-get remove 包名 apt se

前文 Ubuntu 16.04 新特性中我们已经介绍过,随着 Ubuntu 16.04 LTS 的发布,Ubuntu 的软件包管理命令也发生了变化,新系统采用了 Debian 项目中所使用的 APT(Advanced Package Tool)来完成各种的不同的任务,ATP 命令全面取代了我们之前在 Linux 软件包管理基本操作入门中所介绍的 apt-get.apt-cache 等功能. ATP 在创建之初便是为了解决大量软件包管理所遇到的问题,希望结束类似 Linux 早期系统依赖的一大弊病

mariadb install on Ubuntu 16.04.1 LTS

最近在尝试基于Ubuntu 16.04.1 LTS server 部署openstack ,在部署的过程中遇到mariadb 无法正常链接. 问题 参照openstack 官方文档安装mariadb,安装后遇到无法在本地登录的问题 $mysql -u root -p $mysql -h localhost -u root -p 报错如下 mysql (mariadb) ERROR 1698 (28000): Access denied for user 'root'@'localhost' 但使

ubuntu 16.04利用docker搭建java+tomcat+nginx反向代理/动静分离

ubuntu 16.04利用docker搭建java+tomcat+nginx反向代理 新建两个docker容器 docker run -it --name Tomcat-mysql -v /mnt:/mnt -p 8866:80 -p 33006:3306 ubuntu /bin/bash docker run -itd --name webserver -p 8888:80 -v /mnt/:/mnt/ ubuntu /bin/bash [email protected]:~# docker

install the Mondo Rescue utility in Ubuntu 12.04 or 12.10.

  1. Open a terminal window. 2. Type in the following commands, then hit Enter after each. wget ftp://ftp.mondorescue.org/ubuntu/`lsb_release -r|awk '{print $2}'`/mondorescue.sources.listsudo sh -c "cat mondorescue.sources.list >> /etc/apt/sour

Install greenplum cluster on ubuntu 16.04

规划:1个msater, 2个segments 环境:ubuntu 16.04 Greenplum Version: 'postgres (Greenplum Database) 5.3.0 build 2155c5a-oss 1.安装 sudo add-apt-repository ppa:greenplum/db sudo apt-get update sudo apt-get install greenplum-db-oss 2. 配置/etc/hosts Edit the /etc/ho

Ubuntu 16.04安装MinGW32(在/etc/apt/sources.list里添加源)

Ubuntu 16.04下直接使用命令安装MinGW32: sudo apt-get install mingw32 但是,会报错: Unable to locate package mingw32 解决办法如下: sudo gedit /etc/apt/sources.list //在sources.list末尾添加,保存 deb http://us.archive.ubuntu.com/ubuntu trusty main universe sudo apt-get update sudo