Hamsa K
4 min read | 6 months ago

How to Install JAVA on Ubuntu 18 04 bionic

Install Java13 on ubuntu 18.04

Oracle Java JDK (Java Development Kit) is a development environment for developing applications and tools based on Java. It is used for testing applications, and program development alike, using the Java programming language.there is another option as open Java JDK / JRE (an open-source alternative) using apt-get repository.

First we will check with openjdk with default packages

Step 1: Install openjdk

root@ubuntu18:~# apt update
root@ubuntu18:~ apt install default-jdk

Now you can check java version by below command.

root@ubuntu18:~# java -version
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.118.04, mixed mode, sharing)

Step 2: Install java using oracle jdk using PPA repo

Alternatively, it is possible to install Java on Ubuntu using the official Oracle JDK

To install Java 13 on Ubuntu 18.04 and you need to add the linux uprising java PPA repository as shown below.

root@ubuntu18:~# apt install software-properties-common
root@ubuntu18:~# add-apt-repository ppa:linuxuprising/java

now you can install java. Here i am installing java13 on ubuntu 18.04

root@ubuntu18:~# apt update
root@ubuntu18:~# apt install oracle-java13-installer

check java version

root@ubuntu18:~# java --version
java 13.0.2 2020-01-14
Java(TM) SE Runtime Environment (build 13.0.2+8)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)

If you need to set Oracle Java 13 as the default Java version, install the following package if it was not installed.

root@ubuntu18:~# apt install oracle-java13-set-default

Step 3: Setup java environment variables

To set Java home environment variable, you first need to Java installation location by running following command 

root@ubuntu18:~# 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-11-openjdk-amd64/bin/java   1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1111      manual mode
* 2            /usr/lib/jvm/java-13-oracle/bin/java          1091      manual mode
Press <enter> to keep the current choice[*], or type selection number:

open the /etc/environment configuration file and set Java home environment variable like below.

root@ubuntu18:~# vi /etc/environment

Add below line to above file and save it


To load the environments into the current session, run below command

root@ubuntu18:~# source /etc/environment

Finally check java home environment variable setting, run the command below

root@ubuntu18:~# echo $JAVA_HOME



Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy