Install Java On Ubuntu 20.04 LTS

Tutorial To install JAVA On Ubuntu 20.04 LTS

We will install JAVA, JRE, and JDK in this tutorial post. We hope you know the differences between JRE and JDK.

JDK: Java Development Kit or JDK  is a development environment that is used for developing Java Applications.

JRE: JAVA Runtime Environment or JRE is for running Java applications. It is a part of JDK.

Install Java on Ubuntu 20.04 LTS

Install OpenJDK or Oracle Java as per your requirement.

Install OpenJDK In Ubuntu 20.04 LTS

First, update the repository index.

sudo apt update

Install OpenJDK JDK In Ubuntu 20.04 LTS

JDK ( Default JDK 11)

sudo apt install -y default-jdk

Java JDK 11

sudo apt install -y openjdk-11-jdk

Java JDK 8

sudo apt install -y openjdk-8-jdk
JDK Headless

Default JDK ie JDK 11

sudo apt install -y default-jdk-headless

Java JDK 11

sudo apt install -y openjdk-11-jdk-headless

Java JDK 8

sudo apt install -y openjdk-8-jdk-headless

Install OpenJDK JRE


Default JRE ie JRE 11

 sudo apt install -y default-jre

Java JRE 11

sudo apt install -y openjdk-11-jre

Java JRE 8

sudo apt install -y openjdk-8-jre
JRE Headless

Default JRE ie JRE 11

sudo apt install -y default-jre-headless

Java JRE 11 ###

sudo apt install -y openjdk-11-jre-headless

Java JRE 8

sudo apt install -y openjdk-8-jre-headless

Install Oracle Java In Ubuntu 20.04 LTS

There is no separate Java Runtime Environment as  Oracle JDK v9.x and above now includes JRE as well.

Download Oracle Java JDK

You can use either the command line or browser to download the JDK in Ubuntu 20.04 LTS.

Go to the Oracle JDK and download the .deb package for the easy installation.

Download Oracle Java JDK 14

Oracle Java JDK 11 (LTS)

Oracle Java JDK 8

In an alternative method, you can download and install Oracle JAVA via command line:

wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie"

Install Oracle Java JDK In Ubuntu 20.04 LTS using the apt command.

For Oracle Java JDK 14

sudo apt install -y ./jdk-14.0.1_linux-x64_bin.deb

For Oracle Java JDK 11 (LTS)

sudo apt install -y ./jdk-11.0.7_linux-x64_bin.deb

For Oracle Java JDK 8

sudo tar -zxvf jdk-8u251-linux-x64.tar.gz -C /usr/lib/jvm/

By default, If you install Oracle JDK via .deb package then it will be installed in /usr/lib/jvm directory

Create a symbolic link for Java with Oracle JDK.

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-14.0.1/bin/java 1

Run the update-alternatives command to set the default java version. You will see multiple options if you have different versions installed in your system:

sudo update-alternatives --config java

Run the following command to verify your JAVA version.

java -version

Setup Environmental Variables In Ubuntu 20.04 LTS

You can create a file in /etc/profile.d directory to place the variables for your users.

sudo nano /etc/profile.d/

Now, change the variables path based on the Java location in your Ubuntu 20.04 LTS.

export PATH=$PATH:/usr/lib/jvm/java-11-openjdk-amd64/bin/
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/
export J2SDKDIR=/usr/lib/jvm/java-11-openjdk-amd64/

Load the environments with the following command:

source /etc/profile.d/

If you want to set the environment variables for a particular user, you need to place the above variables in the following file.

~/.bash_profile file.

READ More Relevant Stuff:  9+ Best Linux Screen Recorder On Ubuntu 20.04 LTS

Leave a Reply

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