How to Install Java JDK on Ubuntu 22.04

By Ajoy Kumar 6 Min Read
How to Install Java JDK on Ubuntu

Java is one of the world’s most popular and widely used computer programming languages. It is an object-oriented language and is very easy to learn. It is used in the development of system software, online applications, Android applications, and more.

If you are interested in these fields, you should know how to install the Java JDK (Java Development Kit) on Ubuntu. Here, we will learn how to install OpenJDK and Oracle JDK on Ubuntu.

How to Install OpenJDK on Ubuntu using Terminal

OpenJDK is the default Java platform for the Ubuntu operating system. There are two different ways to install Java on Ubuntu: Default Java and the Latest Java. You can install either version. Let’s discuss how you can install them.

1. Installing Default Java JDK

It is always a good option to install the default version of Java JDK if you are unsure which version is compatible with your installed Ubuntu version. Here are the steps to install the default version of OpenJDK on your Ubuntu system.

1. Open the Terminal application. For that, you can use the Ctrl + Alt + T shortcut key.

2. It will open the Terminal. Here, run this command to update the Ubuntu and software repository on your system:

sudo apt update

3. After that, you can check whether Java JDK is pre-installed or not. Sometimes, the Ubuntu system comes pre-installed with Java. If your Ubuntu system has Java already installed, you can skip this step and proceed to the installation of Eclipse IDE for Java programming. Or, you can update to the latest version of Java. Now, to check, run the following command:

java --version
Checking Java Version

4. If you get the following output, “Command ‘java’ not found, but can be installed with:“, you can follow the following steps to install the default version of Java JDK.

5. To install the default version of Java JDK, you can run the following command:

sudo apt install default-jdk
Install Default Java JDK

Note: JRE is included in the JDK package. If you need only JRE, install the default-jre package by running this terminal command: sudo apt install default-jre

2. Installing the Latest Version of Java JDK

Now, let us discuss how to install the latest version of Java JDK. For that, you can follow the steps mentioned below:

1. If you want to install the latest version of Java JDK, then run the mentioned command. Currently, Java 18 is the latest version of Java for Ubuntu.

sudo apt install openjdk-18-jdk
Installing Java using Terminal

2. Run this command in the Terminal to see if Java JDK is installed or not.

java --version

3. If you get something like this, it means Java JDK is installed on your Ubuntu System.

Note: Now, if you want to install JRE only, then run this command: sudo apt install openjdk-18-jre

How to Install OpenJDK on Ubuntu via Software Center

If you don’t want to use the Linux Terminal, you can install the latest version of OpenJDK on Ubuntu using the Ubuntu Software Center. It is the easiest method to install any software or Java JDK on Ubuntu.

To do so, follow these steps:

1. Click the Show Application button (with nine dots) at the bottom of the page.

2. Now, search for Ubuntu Software and open it.

3. Here on the search bar, search for OpenJDK. Now, click on OpenJDK from the listing.

Searching OpenJDK on Ubuntu Software

4. Click the Install button, enter the password to authenticate the installation, and wait for the installation to complete.

Click on Install to get OpenJDK

That’s it! This is how you can install the latest version of OpenJDK on Ubuntu. Now, let us discuss how we can install the Oracle version of Java JDK on Ubuntu.

How to Download and Install Oracle Java on Ubuntu

The Ubuntu repositories do not provide the Oracle Java package. However, you can download the Oracle Java package from the official website.

To do so, follow the steps below:

1. Download the Oracle Java JDK Installer file. For that, visit the link and download the x64 Debian Package file.

Downloading Oracle Java JDK

2. Once the download is complete, go to the location where you saved the DEB file.

3. Right-click on the file and click Open With Other Application > Software Install.

Software Installer

4. Now, it will open the Ubuntu Software Center.

5. Now click the Install button to start installing Oracle Java on your system.

Install Oracle Java

Conclusion

That’s it; this is how you can install OpenJDK and Oracle JDK on your Ubuntu operating system. However, if you have multiple versions of Java installed, you can select one version as the default. For that, you can check out our guide on; how to switch between Java versions. Now to develop Java programs, you can install Eclipse IDE on Ubuntu.

We hope this article was helpful to you. However, if you have any questions regarding the installation process, please ask in the comments section below. We are always there to assist you. Happy programming!

TAGGED:
Share This Article
Follow:
He is a prominent tech writer with over six years of experience and the founder of TheCoderWord. He delivers high-quality content revolving around troubleshooting and how-to guides for Windows, Linux, macOS, Chrome, and more.
Leave a comment

Leave a Reply

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