• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install Java on Ubuntu 20.04

Written by Admin, Updated On April 26, 2020
java, ubuntu
How to Install Java on Ubuntu 20.04

This tutorial will cover how install Java on Ubuntu 20.04. Java is one of the most popular programming language used to build flexible and maintainable applications and systems.

Java comes in two different implementations OpenJDK and Oracle Java. Oracle java provides commercial features. It’s license allows only non-commercial use of software, for personal use or development use.

The default Ubuntu 20.04 repositories include two OpenJDK packages, Java Runtime Environment (JRE) and Java Development Kit (JDK).

  • JRE (Java Runtime Environment) – It includes a set of software tools, classes and binaries that require for the execution of Java applications.
  • JDK (Java Development Kit) – It is development environment and needed for the development of Java application. It includes an interpreter, a compiler, an archiver, and other software tools.
  • OpenJDK – It’s an open-source implementation of JDK. If you are not sure which Java package to install then you should stick to the default OpenJDK.

Prerequisites#

You should have a Ubuntu 20.04 instance with a system user with sudo privileges.

Installing OpenJDK 11#

Currently while writing this article, latest LTS Java development and runtime platform is OpenJDK 11. Run the following commands to update the packages index and install OpenJDK 11 JDK package.

sudo apt update
sudo apt install openjdk-11-jdk

Once the installation is complete, you can verify it by checking the Java version:

java -version

It should show output as below:

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)

All done! Java is installed on your Ubuntu 20.04 system.

Installing OpenJDK 8#

Till date the previous Java 8 LTS version is widely used. If you required Java 8, you can install it using following commands:

sudo apt update
sudo apt install openjdk-8-jdk

Check the installation by verifying the Java version:

java -version

It will show output like as below:

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)

That’s it. Java 8 is successfully installed on your Ubuntu system.

Set the default Java version#

You can set the default Java version, If you have multiple Java versions installed on your Ubuntu system. First of all, check the current default version by typing:

java -version

To change the default version use the update-alternatives command:

sudo update-alternatives --config java

It should show output like this:

There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      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

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

It will show the list of installed Java versions. Select the version which you want to set as default by entering number and hit Enter key.

JAVA_HOME Environment Variable#

The JAVA_HOME environment variable holds the Java installation location which used by the Java applications.

At first, use update-alternatives command to find where the Java versions are installed:

sudo update-alternatives --config java

It will show the path where Java is installed. In this example the installation paths are as follows:

  • OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java
  • Java 8 is located at /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java

Now, open the /etc/environment file by typing:

sudo nano /etc/environment

To set Java 8 as default, set Java 8 installation path to JAVA_HOME as given below, at the end of file:

JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"

Next, Save and exit the text editor. Finally, issue the source command as follows.

source /etc/environment

To confirm the Java environment variable setting, run the command.

echo JAVA_HOME

You should see the path to the Java installation:

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

Uninstall Java#

Uninstall of Java is simple process like any other packages installed with apt:

For example, to uninstall the openjdk-11-jdk package simply run:

sudo apt remove openjdk-11-jdk

Conclusion#

The latest LTS version OpenJDK 11 and previous LTS version OpenJDK 11 are available in the default Ubuntu 20.04 repositories. The installation is a very simple and straightforward task. You learned how to install different java version on Ubuntu 20.04.

If you have any query or suggestion, feel free to leave a comment.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Google Chrome Web Browser on Ubuntu 20.04
Next Article   How to Install WordPress with Apache on CentOS 8

Related Posts

  • How to Install Apache, MySQL, PHP (LAMP) on Ubuntu 22.04

    How to Install LAMP on Ubuntu 22.04

    March 20, 2023
  • How to Install LEMP Stack on Ubuntu 22.04

    How to Install LEMP Stack on Ubuntu 22.04

    March 18, 2023
  • How to Install Memcached on Ubuntu 22.04

    How to Install Memcached on Ubuntu 22.04

    March 16, 2023

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install PHP 8.2 on Debian 11
    How to Install PHP 8.2 on Debian 11 Linux February 24, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook