Raspberry Pi

How to install Java Development Kit or JDK on a Raspberry Pi

The JDK is a java development kit that is used to develop different applications in Java programming and also for testing different Java programs. Moreover, the JDK package also contains the libraries of JRE (Java Runtime Environment) and JVM (Java Virtual Machine). The JDK can be installed easily on the Linux distributions and mostly it comes with the default repository of the Linux-based operating systems.

The Raspberry Pi is also a Debian-based Linux distribution in which we can install the JDK through its default repository. In this write-up, the installation methods of installing the JDK on Raspberry Pi have been discussed.

Method 1: How to install JDK on Raspberry Pi through apt repository

We can install the Java Development Kit’s package on the Raspberry Pi OS through the default repository of the Raspberry Pi, but before proceeding towards the installation, it is recommended to update and also upgrade all the packages of the repository by using the command:

$ sudo apt update && sudo apt upgrade -y

Once all the packages of the repository are up to date, we will install the JDK package with the execution of the command:

$ sudo apt install default-jdk -y

To confirm the installation of the JDK package, we will check the version of the installed JDK using the command:

$ java --version

The JDK package of Java has successfully been installed on the Raspberry Pi, now, if you want to uninstall the java package from the Raspberry Pi, run the command:

$ sudo apt purge default-java* -y

How to install the latest 17.0.2 JDK on Raspberry Pi

Though the above method of installing the JDK package from the repository of Raspberry Pi is easy and fast, it doesn’t install the latest version of JDK package. Nowadays, the latest version of JDK is 17.0.2 which can be installed by using the sdkman package manager, for those who are not familiar with SDKMAN package manager, SDKMAN is a tool for managing parallel versions of different software development tool kit on operating systems like iOS, Android, and Linux. We can install, update, and uninstall different applications available in the library of the SDK manager.

How to install the SDKMAN on Raspberry Pi

We will first install the SDKMAN on the Raspberry Pi OS, for this purpose, we will use the curl command to download it from its official website using the command:

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

The “s” flag is used with the curl command to download the specified certificate file, then we will use the source command to read and execute of the SDKMAN file downloaded with the curl command:

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

With the successful execution of the above command, the SDK manager has been installed, to verify the installation, we will check the version of installed SDK:

$ sdk version

How to install JDK using the SDKMAN on Raspberry Pi

After the successful installation of the SDKMAN, we will list down all the packages of JDK available in the library of SDK using the command:

$ sdk list java

A list will be displayed, scroll down to search the “Temurin” vendor and note down the “Identifier” against the 17.0.2 version:

Press “q” to quit the SDKMAN Java list and run the command to install the Java 17.0.2 version provided by the Temurin vendor using the SDKMAN package manager:

$ sdk install java 17.0.2-tem

At the completion of the installation of JDK 17.0.2, it will set as the default, to cross-check the status of the Java, we will check its version using the command:

$ java --version

To uninstall the installed JDK package using the SDK manager, we will use the command:

$ sdk uninstall java 17.0.2-tem

Conclusion

Many applications are based on the Java language, and to manage these applications we need a JDK package. The JDK package can be installed using the default repository of the Raspberry Pi but the package available in the repository is not the latest version. In this write-up, we have discussed two different methods for the installation of the JDK on Raspberry Pi using its default repository as well as the SDKMAN.

About the author

Hammad Zahid

I'm an Engineering graduate and my passion for IT has brought me to Linux. Now here I'm learning and sharing my knowledge with the world.