Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Install Java on Ubuntu 22.04 - DesignLinux

Dec 25 2022
designlinux 0 Comments
How to Install Java on Ubuntu 22.04

In this tutorial we will show how install Java on Ubuntu 22.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 22.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 22.04 instance with a system user with sudo privileges.

How to Install Java on Ubuntu 22.04#

Perform the following steps to install Java on Ubuntu 22.04:

Step 1 – Update System#

First of all you have to update your system using the below given command:

sudo apt update

Step 2 – Install OpenJDK#

By default Ubuntu 22.04 includes Open JDK 11, which is an open-source variant of the JRE and JDK.

sudo apt install openjdk-jdk

Step 2 – Verify Installation#

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.17" 2022-11-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-3ubuntu1, mixed mode, sharing)

All done! Java is install on your Ubuntu 22.04 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-19-openjdk-amd64/jre/bin/java   1191      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
  • Oracle Java is located at /usr/lib/jvm/java-11-oracle/jre/bin/java

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

sudo nano /etc/environment

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

JAVA_HOME="/usr/lib/jvm/java-11-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-11-openjdk-amd64

Uninstall Java#

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

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

sudo apt remove openjdk-jdk

Conclusion#

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

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

Related

Tags: java, jdk, ubuntu

How to Install Jenkins on Ubuntu 22.04

Prev Post

25 Outstanding Backup Utilities for Linux Systems in 2023

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
  • 71
  • 1,054,843

DesignLinux.com © All rights reserved

Go to mobile version