How to install JDK on Ubuntu 22.04

JDK is a Java Development Kit that contains the packages of Java including JRE(Java Runtime Environment), JVM (Java Virtual Machine), and JLS (Java Language Specification). JDK package should be installed on Ubuntu, if you want to use the Java programming language which is used for the development of many applications.

JDK package can be installed on the latest version of Ubuntu by various methods which are being discovered in this write-up.

How to install JDK on Ubuntu 22.04

Jdk package comes in the default repository of Ubuntu, which can be easily installed using the apt package manager:

$ sudo apt install default-jdk -y

To check the installed version of JAVA, we will run the command:

$ java -version

Java has been installed but its version is 11 where as at the time of writing this write-up, the latest version of Java is 18, so we will uninstall this version of JDK using the command:

$ sudo apt purge default-jdk -y

How to install the latest version of Java on Ubuntu 22.04

To install the latest versions of Java, we will use the SDK package manager which contains the different versions of the applications in its repository and we have choice to install the version of the particular application by our own wish. The SDK package manager is available for IOS, android, and Linux operating systems, and can be installed on Ubuntu using the command:

$ curl -s “https://get.sdkman.io” | bash

Now to read and execute the sdk manager, we will use the source command:

$ source “$HOME/.sdkman/bin/sdkman-init.s”

To verify the installation of the sdk, we will check its installed version:

$ sdk version

Now when the SDK has been installed, we will open the versions available of JAVA on skd manager by using the command:

$ sdk list java

A list of all the versions of Java by different vendors is displayed, scroll down till you find the vendor “Temurin” and click on the latest release of the Java:

Quit the list by pressing the “q” key and run the below-mentioned command to install the latest version of Java:

$ sdk install java 18.0.1-tem

To confirm the installation, we will check the version of JAVA:

$ java --version

The latest version of Java has been installed, now if we want to uninstall it, we have to use the command:

$ sdk uninstall java 18.0.1-tem

Conclusion

JDK is Java Development Kit that is used to install Java on the operating system including all the necessary tools of Java. In this write-up, the default package of JDK has been installed but it contains the older version of Java, so we have explored the sdk package manager method to install the latest Java version on ubuntu 22.04.