We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Install Java 11 on Ubuntu 22.04|20.04|18.04

Learn how to – Install Java 11 on Ubuntu 22.04|20.04|18.04.

In this tutorial, I’ll walk you through the steps to install Oracle Java 11 on Ubuntu 22.04|20.04|18.04. Java 11 is a long-term support (LTS) release made available to the General public on 25 September 2018 and is production-ready.

You can install Java 11 on Ubuntu 22.04|20.04|18.04 either from one of the following methods:

  1. Java SE Development Kit 11 (JDK 11)
  2. OpenJDK 11

This guide will cover the installation of Oracle Java 11 on Ubuntu 22.04|20.04|18.04 from both methods.

Method 1: Install Java 11 from Upstream repo / PPA – Recommended

For Ubuntu 22.04/20.04 , run:

sudo apt update
sudo apt install openjdk-11-jdk

Ubuntu 18.04

sudo add-apt-repository ppa:linuxuprising/java
sudo apt update
sudo apt install oracle-java11-set-default

If you don’t want to set Java 11 as default, then install:

sudo apt install oracle-java11-installer

Conform Java verison:

$ java -version
openjdk version "11.0.17" 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu222.04, mixed mode, sharing)

Setting Default version of Java

If you have more than one version of Java installed in your system, you can refer to our guide on how to set default version for all applications.

How to set default Java version on Ubuntu / Debian

Method 2: Manually install OpenJDK 11 on Ubuntu 22.04|20.04|18.04

OpenJDK is a free and open-source implementation of the Java Platform, Standard Edition licensed under the GNU General Public License version 2.

Check the latest release of OpenJDK 11 before running the command below:

wget https://download.java.net/openjdk/jdk11/ri/openjdk-11+28_linux-x64_bin.tar.gz

This will download OpenJDK 11 tar file to your working directory. After the download, extract the archive

tar zxvf openjdk-11+28_linux-x64_bin.tar.gz

Move the resulting folder to /usr/local/

sudo mv jdk-11* /usr/local/

Set environment variables

sudo vim /etc/profile.d/jdk.sh


export JAVA_HOME=/usr/local/jdk-11
export PATH=$PATH:$JAVA_HOME/bin

Source your profile file and check java command

$ source /etc/profile 
$ java -version
openjdk version "11.0.2" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

$ which java

Method 3: Manually Install Java SE Development Kit 11 (JDK 11)

Download the latest release of JDK 11.

wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie" https://download.oracle.com/otn-pub/java/jdk/11.0.12%2B8/f411702ca7704a54a79ead0c2e0942a3/jdk-11.0.12_linux-x64_bin.deb

Then install the package with the dpkgcommand

sudo apt install ./jdk-11.0.12_linux-x64_bin.deb

If you encounter dependency issues, then run:

sudo apt -f install
sudo dpkg -i jdk-11.0.12_linux-x64_bin.deb

Set environment variables

sudo vim /etc/profile.d/jdk.sh


export JAVA_HOME=/usr/lib/jvm/jdk-11.0.12/
export PATH=$PATH:$JAVA_HOME/bin

Source the file and confirm Java version installed

$ source /etc/profile.d/jdk.sh
$ java -version
java version "11.0.12" 2021-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode

Recommended books:

For CentOS 7 & Fedora Linux distributions, refer to:


Your Cart is Empty

Back To Shop