How to Install Java on Ubuntu 20.04 LTS

In this article, We are going to perform How to Install JAVA on Ubuntu 20.04 LTS. Here we are installing OpenJDK 11 and 8 stable version on Ubuntu 20.04 LTS

Introduction

OpenJDK is free and open-source implementation of the Java SE Platform.

Prerequisites

  • Ubuntu Server 20.04 LTS
  • SSH access with sudo privileges

How to Install Java on Ubuntu 20.04 LTS

Here We are going to install OpenJDK 11 and OpenJDK 8 stable version on Ubuntu 20.04 LTS

How to Install OpenJDK 11 on Ubuntu 20.04 LTS

Lets install OpenJDK 11 on ubuntu 20.04 LTS using below commands.

$ sudo apt update

$ sudo apt install openjdk-11-jdk

Lets verify java version

$ java -version

Output:

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)

How to Install OpenJDK 8 on Ubuntu 20.04 LTS

Lets install OpenJDK 8 on ubuntu 20.04 LTS using below commands.

$ sudo apt update

$ sudo apt install openjdk-8-jdk

Lets verify java version

$ java -version

Output:

openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1ubuntu1-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

Set Default Java Version using update alternatives

If you have installed multiple Java versions on your system and you want to set Default Java version on Ubuntu. Lets set Default Java Version using update alternatives command,

$ sudo update-alternatives --config java

It prompts for selecting by 0,1,2..so choose accordingly:

sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status
------------------------------------------------------------
   0 /usr/lib/jvm/zulu-11-amd64/bin/java 1113900 auto mode
   1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
* 2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
   3 /usr/lib/jvm/zulu-11-amd64/bin/java 1113900 manual mode

Press <enter> to keep the current choice[*], or type selection number: 1

To verify the if java version switched

$ java -version

Setting the JAVA_HOME Environment Variables

To define the environment variable open the below file:
$ sudo nano /etc/environment
Paste the below variable into the file:

For OpenJDK 8 java is installed at /usr/lib/jvm/java-11-openjdk-amd64/bin/java location

For OpenJDK 11 Java is installed at /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java location

/etc/environment
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"

Load the environment variable using below command

$ source /etc/environment

Lets verify JAVA_HOME variable

$ echo $JAVA_HOME

Output:

/usr/lib/jvm/java-11-openjdk-amd64

If you seeing output like above then we have successfully set up the Java Home on Ubuntu.

Conclusion

In this article, We are going to perform How to Install JAVA on Ubuntu 20.04 LTS, configured JAVA_HOME, verified installed version.

Related Articles:

Install Zulu OpenJDK Version 11 on Ubuntu 20.04/18.04/16.04 LTS

FOSS TechNix

FOSS TechNix (Free,Open Source Software's and Technology Nix*) founded in 2019 is a community platform where you can find How-to Guides, articles for DevOps Tools,Linux and Databases.

2 thoughts on “How to Install Java on Ubuntu 20.04 LTS”

  1. Java is an amazing programming platform. They provide real-time development environment. I love to use Netbeans for java programming, thanks for the valuable post. I think installing java in Ubuntu will be a learning lesson for me.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link