Jump to content

How to Install Java in Ubuntu


Linux Hint

Recommended Posts

Java has been ranked among the most powerful programming languages, and millions of devices run on Java. Knowing how to install Java on Ubuntu is essential for someone who is looking to learn Java or run the Java-based applications in Ubuntu. This post will guide you on installing Java in Ubuntu. The steps that are detailed here will work on Ubuntu 18.04, 20.04, 22.04, and newer versions.

Step-by-Step Guide on Installing Java in Ubuntu

Installing Java in Ubuntu is easy. You only need a user account with sudo privileges and a stable internet connection. There are different Java platforms that you can use including Java Standard Edition, JavaFX, etc. For our case, we will focus on the Java Standard Edition which offers the Java Development Kit (JDK) and the Java Runtime Environment (JRE).

When installing Java, you need JDK and JRE. JDK lets you seamlessly develop the Java applications on Ubuntu, while JRE offers an environment to run the Java-based applications. The two platforms are free and open-source for anyone to install.

That being said, here are the steps to install Java in Ubuntu.

Step 1: Refresh Apt

When you want to get the latest packages from the Ubuntu repositories, you should use the “apt” command to update the repositories.

$ sudo apt update

word-image-177912-1.png

Next, let’s confirm if Java is available in our Ubuntu. For that, check the Java version. If Java is installed, you will see the JDK version displayed on the terminal. Otherwise, you will get an output that is similar to the one in the following which shows that Java is not installed.

word-image-177912-2.png

Step 2: Install JRE

By default, when you install JDK, it should automatically install the equivalent JRE package. However, if JRE doesn’t work as required or you only want to run the Java-based applications without any development, you can install it as follows:

$ sudo apt install default-jre

Press “y” when prompted. Then, let the installation proceed to completion. All the required packages and dependencies will get installed and you will have JRE available on your Ubuntu.

word-image-177912-3.png

You will see the “done” message that confirms the installation’s success at the last line on your terminal.

word-image-177912-4.png

Step 3: Install JDK

Ubuntu supports Java. From the official Ubuntu repository, you can install OpenJDK 11. If you choose to run the following command, OpenJDK 11 will automatically get installed:

$ sudo apt install default-jdk

However, you have room to specify a different JDK version. Your project may require the latest JDK versions such as OpenJDK 18. Luckily, when installing JDK, you can specify any version that you want to install.

For instance, let us install OpenJDK 18. For that, we will change our command as follows:

$ sudo apt install openjdk-18-jdk

Once you confirm the installation, OpenJDK will install and you will now have Java available on your system and can start writing your code and build it successfully.

word-image-177912-5.png

At this point, you can check the available JDK version on your Ubuntu.

word-image-177912-6.png

The given output confirms that we installed OpenJDK 18 on our Ubuntu. That’s how you can comfortably install Java in Ubuntu. These steps will work on the earlier-mentioned Ubuntu versions. Besides, you can apply the same on other distros such as Linux Mint.

Conclusion

Java is a powerful programming language that you can use for different projects including desktop and mobile applications. To build the Java projects on Ubuntu, you must install JDK and JRE. Moreover, if you want to run the Java-based applications, you must have JRE on your Ubuntu. The steps that are covered in today’s post will guide you on what steps you should take to install Java in Ubuntu. Have fun!

View the full article

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...