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:
- Java SE Development Kit 11 (JDK 11)
- 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 Oracle 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.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, 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
Add:
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
/usr/local/jdk-11.0.2/bin/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 dpkg
command
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
Add:
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