Raspberry Pi

How to Update Java on Raspberry Pi

Java is one of the most versatile and widely used programming languages adopted by millions of devices all over the world. With Java, you will be able to run high end applications, servers, mobile applications and more. Most of these applications require an updated Java version because it adds more privacy and security to your system as well as the applications you use on the system.

If you have currently installed an updated Java version on a Raspberry Pi system and are searching for a way to update it to the latest version, you should follow this article for a brief guide.

How to Update Java on Raspberry Pi

To update Java on Raspberry Pi, ensure that your Raspberry Pi system does include the previous older version of Java and for that, you can use the following command:

$ java --version

Then perform the following steps to update Java on Raspberry Pi:

Step 1: Download Java’s Latest Version Source File

First, use the following command to download Java’s latest version source file on Raspberry Pi:

$ wget https://download.oracle.com/java/19/latest/jdk-19_linux-aarch64_bin.tar.gz

Note: The latest Java version only supports 64 Bit Raspberry Pi OS, so don’t forget to perform these steps on 64Bit OS.

Step 2: Extract the Java Source Content

Now, move the Java latest version source content to the /opt directory using the following command:

$ sudo tar xvf jdk-19_linux-aarch64_bin.tar.gz -C /opt

Step 3: Install Java Latest Version

Next run the following command to install Java as an alternative to the previously installed Java version and assign the priority number to it.

$ sudo update-alternatives --install /usr/bin/java java /opt/jdk-19.0.2/bin/java 1000

Similarly, use the following command to install Java Compiler as an alternative to previously installed Java compiler on Raspberry Pi and set its priority too.

$ sudo update-alternatives --install /usr/bin/javac javac /opt/jdk-19.0.2/bin/javac 1000

Step 4: Configure Java Version

After installing the latest Java version on Raspberry Pi, it’s now time to configure the default Java for Raspberry Pi system and for that run the following command:

$ sudo update-alternatives --config java

Note: You can skip this step if you don’t have any Java version installed on Raspberry Pi.

Select “1” to keep the updated Java version for Raspberry Pi system.

You can also select the default Java Compiler for Raspberry Pi system using the following command:

$ sudo update-alternatives --config javac

Select “1” as the default Java Compiler and once it’s done, you can confirm the Java version using the following command:

$ java --version

You can also confirm Java Compiler version using the following command:

$ javac --version


You can update Java on the Raspberry Pi system by downloading the tar.gz file from the official source and then extracting the content to /opt directory. After that you have to perform the Java installation and then update the latest version with the older version using the “update-alternatives” command. Ensure selecting the latest Java and Java Compiler directory and run then run the version command to confirm updating the Java version on Raspberry Pi system.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.