Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How To Install Java with Apt on Ubuntu 20.04 - DesignLinux

Apr 15 2021
designlinux 0 Comments

Java is one of the most popular programming languages and the JVM (Java’s virtual machine) is the run-time environment to run Java applications. These two platforms are required for much popular software that includes Tomcat, Jetty, Cassandra, Glassfish, and Jenkins.

In this article, you will learn how to install Java Runtime Environment (JRE) and the Java Developer Kit (JDK) using the default apt package manager on Ubuntu 20.04 and Ubuntu 18.04.

Installing the Default JRE in Ubuntu

The painless way for installing Java is to use the version that comes with Ubuntu repositories. By default, Ubuntu packages with OpenJDK 11, which is an open-source alternative of the JRE and JDK.

To install default Open JDK 11, first update the software package index:

$ sudo apt update
Update Ubuntu
Update Ubuntu

Next, check for Java installation on the system.

$ java -version

If Java is not currently installed, you will get the following output.

Command 'java' not found, but can be installed with:

sudo apt install openjdk-11-jre-headless  # version 11.0.10+9-0ubuntu1~20.04, or
sudo apt install default-jre              # version 2:1.11-72
sudo apt install openjdk-8-jre-headless   # version 8u282-b08-0ubuntu1~20.04
sudo apt install openjdk-13-jre-headless  # version 13.0.4+8-1~20.04
sudo apt install openjdk-14-jre-headless  # version 14.0.2+12-1~20.04

Now run the following command to install the default OpenJDK 11, which will provide Java Runtime Environment (JRE).

$ sudo apt install default-jre
Install Java in Ubuntu
Install Java in Ubuntu

Once Java installed, you can verify the installation with:

$ java -version

You will get the following output:

openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)

Installing the Default JDK in Ubuntu

Once JRE installed, you might also need the JDK (Java Development Kit) in order to compile and run a Java-based application. To install the JDK, run the following command.

$ sudo apt install default-jdk
Install OpenJDK in Ubuntu
Install OpenJDK in Ubuntu

After installation, verify the JDK installation by checking the version as shown.

$ javac -version

You will get the following output:

javac 11.0.10

Setting the JAVA_HOME Environment Variable in Ubuntu

Most of the Java-based software programs use the JAVA_HOME environment variable to discover the Java installation location.

To set the JAVA_HOME environment variable, first, discover where Java is installed by running the following command.

$ readlink -f /usr/bin/java

You will get the following output:

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

Then open /etc/environment file using nano text editor:

$ sudo nano /etc/environment

Add the following line at the end of the file, make sure to replace the location of your Java installation path.

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

Save the file and reload the file to apply the changes to your current session:

$ source /etc/environment

Verify that the environment variable is set:

$ echo $JAVA_HOME

You will get the following output:

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

In this tutorial, you learned how to install Java Runtime Environment (JRE) and the Java Developer Kit (JDK) on Ubuntu 20.04 and Ubuntu 18.04.

Related

Tags: Ubuntu Tips

LFCA: Learn Binary and Decimal Numbers in Network – Part 10

Prev Post

How To Install Jenkins on Ubuntu 20.04/18.04

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 256
  • 614,628

DesignLinux.com © All rights reserved

Go to mobile version