Installing Java on the Raspberry Pi

In this guide, we will show you how to install Java for the Raspberry Pi.

Raspberry Pi Java

Java is a popular and powerful programming language that has a wide range of uses. The Java language is the language that the popular game Minecraft is built with.

In this tutorial, we will be installing the OpenJDK version of Java and not the one provided by Oracle.

The reason for this is that the OpenJDK version of Java is more up to date for ARM-based systems such as the Raspberry Pi. It is also easily obtainable through the Raspbian repository.

There are two possible flavors of Java that you can install. There is the JDK, which stands for “Java Development Kit” and the JRE, which stands for “Java Runtime Environment”.

In this guide, we will be showing you how to install the JDK to your Raspberry Pi. The JDK comes with the JRE but will also allow you to compile your own Java programs as well.

If you only install the JRE, then you will only be able to run pre-compiled programs.

We use Java in our Raspberry Pi Minecraft Server tutorial as it is required for the software to work.

Equipment List

Here is all the equipment that we recommend for this Raspberry Pi Java tutorial.

Recommended

Raspberry Pi 2, 3 or 4

Micro SD Card

Power Supply

Ethernet Cord or WiFi dongle (The Pi 3 and 4 has WiFi inbuilt)

Optional

Raspberry Pi Case

Installing Java to the Raspberry Pi

While we tested this Java installation tutorial on Raspbian Buster, this should also work for both older and newer versions of Raspbian.

1. Before we go ahead and install Java we need first to ensure that everything is up to date.

To update all existing packages, go ahead, and run the following two commands.

sudo apt update
sudo apt upgrade

The update process can take some time if you have a slow network connection, or there is a lot of packages to update.

2. Once the update process has completed, we can proceed to install the latest available version of Java to our Raspberry Pi.

In this guide, you will be installing OpenJDK 11 as it is the latest version of Java available for Raspbian Buster.

We are using the package default-jdk as this will always point to the latest available version of the JDK for Raspbian.

You can install Java to Raspbian by running the following command.

sudo apt install default-jdk

3. Now that we have installed Java, let’s go ahead and quickly run it to make sure everything is working.

To test Java, all we need to do is run the following command on the Raspberry Pi.

java -version

All this command does is get the Java Runtime to print out its version.

If you are running Raspbian Buster, you should get a result similar to the one below.

openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Raspbian-1deb10u1)
OpenJDK Server VM (build 11.0.5+10-post-Raspbian-1deb10u1, mixed mode)

Hopefully, at this point, you will now have Java up and running on your Raspberry Pi.

If you run into any issues or have any feedback on this Raspberry Pi java tutorial, then feel free to drop a comment below.

Leave a Reply

Your email address will not be published. Required fields are marked *