How-To: Install Java on Ubuntu 22.04


Check if Installed

To verify if Java is installed, you can execute the following to check.

$ java -version
$ javac -version

The “javac” is used for compiling java code, while “java” is for running them. The compiler is needed if you intend to develop and test java code.

If they are not installed you can install java using the next steps.

Installing Java via Package Manager

01. Update the package manager repositories

$ sudo apt-get update

02. Install Java. Note that you can install Java from different distributions. The current Default JDK at the time of this writing is JDK 11.

$ sudo apt-get install default-jdk -y

Or installing specific JDK like JDK 8.

$ sudo apt-get install openjdk-8-jdk -y

03. Verify the installation by checking the version again.

$ java -version
$ javac -version

Managing multiple JDK

If there are different version of Java available on the system, the default Java can be changed by using the following command.

$ sudo update-alternatives --config java

In the above example, JDK 8 and 11 are installed. The default is also set to JDK 11. Setting the option to 2 in the selection will change it to Java 8 JDK.

Uninstall Java

Run the following command to remove Java

$ sudo apt-get remove default-jdk

Confirm the removal

Verify if uninstalled correctly. If you have multiple version of Java installed, those need to be specifically removed.

For enquiries, product placements, sponsorships, and collaborations, connect with us at We'd love to hear from you!