VOOZH about

URL: https://linuxconfig.org/how-to-install-java-on-ubuntu-18-10-cosmic-cuttlefish-linux

⇱ Install Java on Ubuntu 18.10 Easily


Skip to content

Objective

The objective of this tutorial is to install Java on Ubuntu 18.10 Cosmic Cuttlefish Linux.

Operating System and Software Versions

  • Operating System: – Ubuntu 18.10 Cosmic Cuttlefish
  • Software: – Java(TM) SE Runtime Environment 8,10 or 11

Requirements

Privileged access to to your Ubuntu 18.10 Cosmic Cuttlefish Linux system is required to perform this installation.

Difficulty

EASY

Conventions

  • # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
  • $ – requires given linux commands to be executed as a regular non-privileged user

Instructions

Install Java using the Ubuntu Open JDK binaries

The recommended and perhabs the simplest way to install Java on Ubuntu 18.10 Cosmic Cuttlefish is to install open source Java binaries Open JDK from a standard Ubuntu 18.10 package repository:

To install Ubuntu Java Open JDK version 11 execute:

$ sudo apt install openjdk-11-jdk

and for Java Open JDK 8 run:

$ sudo apt install openjdk-8-jdk

Install Java on Ubuntu via PPA

Add PPA Repository

Using Webupd8 Team’s PPA repository we can install Oracle Java on Ubuntu automatically using the apt command.

Webupd8 Team currently maintains Oracle Java 8 PPA repositories for Ubuntu 18.10 Cosmic Cuttlefish.
Let’s start by adding a PPA repository. Select one of the below command based on the Java version you wish to install:

Java version 8

$ sudo add-apt-repository ppa:webupd8team/java

Java version 10

sudo add-apt-repository ppa:linuxuprising/java

Install Java on Ubuntu

Once we add PPA repository as per the above instructions we can move to installing java on Ubuntu. Executing the apt search oracle-java command should now show multiple java versions available for install.

Namely they are java8 and java10.

To install Java 8 execute:

$ sudo apt install oracle-java8-set-default

To install Java 10 execute :

$ sudo apt install oracle-java10-set-default


👁 Install Open JDK java on Ubuntu 18.10 Cosmic Cuttlefish
Install Open JDK java on Ubuntu 18.10 Cosmic Cuttlefish

The above commands will automatically install selected java version and set all necessary java environment variables.

$ java --version
java 10.0.2 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)

Set default Java Version Manually

In case you need to manually switch between installed Java versions start by listing your current java environment variable settings:

$ sudo update-alternatives --get-selections | grep ^java


For more verbose version of the above command execute sudo update-alternatives --get-selections | grep java.

To set java to eg. Java 10 executable run:

$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

 Selection Path Priority Status
------------------------------------------------------------
 0 /usr/lib/jvm/java-10-oracle/bin/java 1091 auto mode
 1 /usr/lib/jvm/java-10-oracle/bin/java 1091 manual mode
* 2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode

Press 

Confirm your selection:

$ sudo update-alternatives --get-selections | grep ^java
java auto /usr/lib/jvm/java-10-oracle/bin/java
javac manual /usr/lib/jvm/java-8-oracle/bin/javac
javadoc manual /usr/lib/jvm/java-8-oracle/bin/javadoc
javafxpackager manual /usr/lib/jvm/java-8-oracle/bin/javafxpackager
javah manual /usr/lib/jvm/java-8-oracle/bin/javah
javap manual /usr/lib/jvm/java-8-oracle/bin/javap
javapackager manual /usr/lib/jvm/java-8-oracle/bin/javapackager
javaws manual /usr/lib/jvm/java-8-oracle/jre/bin/javaws
javaws.real auto /usr/lib/jvm/java-10-oracle/bin/javaws.real

Use the update-alternatives --config JAVA-EXECUTABLE-HERE to change the environmental path to any other java executable binaries as required.

Install Java using the Official Oracle binaries

The following section will describe a manual Oracle Java installation on Ubuntu 18.10. The official binaries can be downloaded from Oracle website as explained below:

Java Download

Point your browser to the official Oracle java download page and download the latest binaries.

We are interested in, for example, Java DEB package. In this tutorial we will be installing the Java 11 jdk-11_linux-x64_bin.debpackage.

Download java package and save it into your home directory:

$ ls ~/jdk-11_linux-x64_bin.deb 
/home/linuxconfig/jdk-11_linux-x64_bin.deb

Install Java on Ubuntu 18.10

Now, that your java download is completed and you have obtained the Oracle JDK DEB package, execute the following dpkg linux command to perform the java Ubuntu installation:

$ sudo dpkg -i ~/jdk-11_linux-x64_bin.deb

Set Defaults

The following linux commands will set Oracle JDK as system wide default. Amend the below commands to suit your installed version:

$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-11/bin/java 1
$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk-11/bin/javac 1
$ sudo update-alternatives --install /usr/bin/javadoc javadoc /usr/lib/jvm/jdk-11/bin/javadoc 1
$ sudo update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/jdk-11/bin/javap 1

Confirm Java Installation

What remains is to check for installed java version:

$ java --version
java 11 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11+28)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11+28, mixed mode)
👁 Install Official Oracle Java package on Ubuntu 18.10 Cosmic Cuttlefish
Install Official Oracle Java package on Ubuntu 18.10 Cosmic Cuttlefish