Home » Tutorial » How to Install Java on Ubuntu 18.04 Linux Operating System

How to Install Java on Ubuntu 18.04 Linux Operating System

Java is the most popular programming language, use to build various type of applications like a desktop application, web application, mobile application, etc. Today I’ll share how to install Java on Ubuntu 18.04 Server.

The Java comes in two different packages, one is Java Runtime Environment (JRE), and another one is the Java Development Kit (JDK).
 
When we need to run a Java-based application or java program, we need only Java Runtime Environment, but if you want to develop Java application, you need to Java Development Kit (JDK). JDK includes both JRE and debugging tools and development libraries.
 
Java also has two different flavors, one is Open JDK, and another one is Oracle Java, both have the same functionalities and capabilities, the only difference is Oracle Java has some more commercial features. The default Java flavor of Linux Operating System is OpenJDK.
 

If you are a little bit confuse to choose between OpenJDK and Oracle Java, you can stick with default OpenJDK available on Ubuntu 18.04.

In this tutorial article, we will walk through the Java installation process on Ubuntu 18.04 machine.

Prerequisites

Before continuing this tutorial, make sure you have Ubuntu 18.04 installed machine and a user to login into the system with sudo privileges.

OpenJDK 8 installation on Ubuntu 18.04

OpenJDK 8 is available in Ubuntu 18.04 Operating system as a default JDK.

To install OpenJDK 8 into Ubuntu 18.04 machine, use the following command:

$ sudo apt update
$ sudo apt install default-jdk

After completion of JDK installation you can verify it by checking the version of Java, as shown below:

$ sudo java –version

If OpenJDK installed you will get the output like below image:

  • Facebook
  • Twitter
  • reddit
  • LinkedIn

Now OpenJDK 8 is installed successfully into your Ubuntu 18.04 machine.

OpenJDK 11 Installation on Ubuntu 18.04

The latest version of Java 11 is not available with default repository of Ubuntu 18.04 operating system. The OpenJDK 11 is available with Backports repository of Ubuntu.

To install OpenJDK into Ubuntu machine first need to add backport repository by using below command:
$ echo 'deb http://ftp.debian.org/debian stretch-backports main' | sudo tee /etc/apt/sources.list.d/stretch-backports.list
  • Facebook
  • Twitter
  • reddit
  • LinkedIn

After adding the repository, update the apt repository package list and install OpenJDK 11 by using the following command:

$ sudo apt update
$ sudo apt install openjdk-11-jdk
  • Facebook
  • Twitter
  • reddit
  • LinkedIn
  • Facebook
  • Twitter
  • reddit
  • LinkedIn

Oracle Java Installation on Ubuntu 18.04 Linux

First, you should be aware of Oracle Java Licence; it is free only for non-commercial use of the software like development and personal use.
 
To install Oracle Java 11, you should use Linux Uprising PPA.

You can follow below steps to install Oracle 11 on Ubuntu 18.04.

Step 1 – Install dependencies

First, you should install Oracle Java 11 dependencies into the system by using the following command:
$ sudo apt install dirmngr gnupg

Step 2 – Import PPA key and enable the repository

To import PPA public key and enable the repository for Oracle Java 11 use below command:
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 73C3DB2A
$ echo 'deb http://ppa.launchpad.net/linuxuprising/java/ubuntu bionic main' | sudo tee /etc/apt/sources.list.d/linuxuprising-java.list

Step 3 – Install Oracle Java 11

Once the repository is added and enable, you are ready to install Oracle Java 11.
 
Now you can update the repository package list and install Java by using the following command:
$ sudo apt update
$ sudo apt install oracle-java11-installer

You will get the screen to accept Oracle license, accept and Java will install.

  • Facebook
  • Twitter
  • reddit
  • LinkedIn
  • Facebook
  • Twitter
  • reddit
  • LinkedIn

Step 4 – Verify Java Installation

After installation of java you can verify by checking the version of Java, as shown below:
$ java –version
  • Facebook
  • Twitter
  • reddit
  • LinkedIn
  • Facebook
  • Twitter
  • reddit
  • LinkedIn

Java default version Setup

If you have installed multiple Java into your Ubuntu machine, you can check the default version of Java by checking the version, as shown below:
$ java -version

The output of the above command will look like below image:

  • Facebook
  • Twitter
  • reddit
  • LinkedIn
  • Facebook
  • Twitter
  • reddit
  • LinkedIn

You can change the default Java version by using “update-alternatives” command, as shown below:

$ sudo update-alternatives --config java
  • Facebook
  • Twitter
  • reddit
  • LinkedIn

You will get the list of all installed Java version on your Ubuntu machine, Enter the number of the version you want to use as a default and press Enter button.

Java Uninstall

If you want to remove Java package from your Ubuntu system, you can uninstall it like any other application with the apt package manager.
 
To uninstall OpenJDK grom your Ubuntu machine you can use below command:
$ sudo apt remove default-jdk

Conclusion

Now you have learned how to install OpenJDK and Oracle Java on Ubuntu operating system.

Related Posts

How to Install CouchDB on Ubuntu 21.04 Linux Operating System

How to Install CouchDB on Ubuntu 21.04 Linux Operating System

The CouchDB is an open-source database system, managed by the Apache Software Foundation. It is fault-tolerant, and schema-free NoSQL database management system.   CouchDB store data in document or files with JSON data structure. Each document contains fields and...

How to add swap space on Ubuntu 21.04 Operating System

How to add swap space on Ubuntu 21.04 Operating System

The swap space is a unique space on the disk that is used by the system when Physical RAM is full. When a Linux machine runout the RAM it use swap space to move inactive pages from RAM. Swap space can be created into Linux system in two ways, one we can create a...

How to Install Nginx on Ubuntu 21.04 Server

How to Install Nginx on Ubuntu 21.04 Server

Nginx is the most potent, open-source, and a high-performance Web server. It can work as a reverse proxy server also, nowadays, is used by most of the most significant websites on the internet. People pronounced “engine x” for Nginx; it is the hot choice for every...

How to Install VirtualBox on Ubuntu 21.04 Linux

How to Install VirtualBox on Ubuntu 21.04 Linux

VirtualBox is an Open Source tool, known as a cross-platform virtualization application or software. It used to run multiple operating systems or virtual machines simultaneously on a single hardware. In this VirtualBox installation tutorial, we will explain the...

Follow Us

Our Communities

More on Ubuntu

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!

0 Comments

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

15 + six =

Shares