How to Install Java in Ubuntu?

Table of Contents
How to install Java in Ubuntu

What is Java?

Java is a computer language that is used to make things like video games, apps, and websites. If you want to install java in ubuntu then, you are at the right place. Today, I will tell you two methods of installing java in ubuntu.

Prerequisites

Before you start, make sure you have:

1. A computer with Ubuntu on it

2. A good internet connection

Ways to Install Java in Ubuntu

There are two ways to get Java on Ubuntu :

1. The first one is Using the Terminal (a special program on your computer)

2. And the second one is downloading Java directly from the website

1. Installing Java Using Terminal

This is the easiest way to install Java on your Ubuntu computer. I suggest you to go with this method.

Step 1: Updating Your System

First, you need to update the system for that pen the Terminal and type the following command:

sudo apt update

Then hit Enter and wait for the system to update.

Step 2: Installing Java

Now, to install java type in the following command into the Terminal:

sudo apt install default-jdk

Then, hit Enter and wait for Java to be installed.

Step 3: Checking if Java is Installed

To make sure Java is installed, type the following command into the Terminal:

java -version

If everything is okay, you'll see the version of Java on your computer.

2. Installing Java by Downloading Directly

This way is a bit harder, but it allows you to choose which version of Java you want.

Step 1: Downloading Java

First, go to the Java website and download the version of Java according to your choice..

Step 2: Unzipping Java

Now, find the file you just downloaded and right-click on it. Choose "Extract Here." This will unzip the file.

Step 3: Setting Up Java

Now open the Terminal at that location and type the following command:

sudo nano ~/.bashrc

This will open a text editor.

At the bottom of the file, you need to add the following lines:

export JAVA_HOME=<JDK_Installation_Directory>

export PATH=$PATH:$JAVA_HOME/bin

NOTE: Replace <JDK_Installation_Directory> with the path to the folder where you unzipped Java.

Now, Save the file and close it.

Step 4: Checking if Java is Installed

To make sure that Java is installed successfully in your ubuntu system, type the following command into the Terminal:

java -version

If everything is okay, you'll see the version of Java on your computer.

Conclusion

So, that is how you can install java in ubuntu without any error. But if you got any error just comment down, and I will surely help you with it.I suggest you go with the 1st method if you are a beginner.

Ubuntu Java Install All Commands

1. sudo apt update
2. sudo apt install default-jdk
3. java -version

Related Content

FAQ

Q 1. Which JDK is best for Java?
In my opinion, JAVA SE 11 or 17 is best. As these are the most used one and reliable.