The OpenJDK 11 version that comes in Raspberry Pi OS’s apt repositories is ancient. It’s so old that recently people using my Minecraft Java Server for Raspberry Pi script have started getting a warning that Minecraft 1.17 will *not* support anything below OpenJDK 16.
In this article I’m going to share a sneaky trick to update your Java to a newer version than is available in apt using snapd. Let’s begin!
The Raspberry Pi 4 is available in different memory configurations all the way up to 8 GB. It’s about the size of a credit card and uses an extremely low amount of power making it ideal for all sorts of projects and ideas!
The Raspberry Pi 400 kit includes everything you need for a full Pi 400 desktop build. The Pi 400 is the fastest Raspberry Pi ever released and comes in the form factor of a keyboard!
Raspberry Pi OS’s repositories have got quite dated for Java. This is happening for other applications as well because we are waiting for the Raspberry Pi OS team to jump to the next version of Debian (the underlying OS that Raspberry Pi OS is built on) which will bring a lot of these offerings more up to date.
To get around this we’re going to use the “snapd” utility to install a much newer version of OpenJDK. We will then use update-alternatives to point our /usr/bin/java to our new JDK installation.
A reboot is required after installing snapd for the first time and it takes a lot longer to install via snap than it would via apt but since the packages are not available this is a great workaround!
OpenJDK Update Instructions
First let’s install snapd and get our reboot out of the way:
sudo apt update
sudo apt install snapd -y
Once your system comes back online let’s install snap core and OpenJDK:
sudo snap install core
sudo snap install openjdk
These steps can take a little while. It’s not unusual to have to wait 5-10 minutes for each step.
Now at this point our new OpenJDK installation is installed and we just need to tell our system to use that for Java using update-alternatives:
sudo update-alternatives --install /usr/bin/java java /snap/openjdk/current/jdk/bin/java 1
sudo update-alternatives --set java /snap/openjdk/current/jdk/bin/java
And that’s it! Go ahead and verify you are using the new Java version like this:
pi@pi:~ $ java -version
openjdk version "16.0.1" 2021-04-20
OpenJDK Runtime Environment (build 16.0.1+9-snap)
OpenJDK Server VM (build 16.0.1+9-snap, mixed mode)
If you need an even newer version of Java than you are getting from the default snap there are some flags to install even newer ones. There are 3 additional release channels. These are in ascending order so the further down the list you go the newer version of OpenJDK it will retrieve:
sudo snap install openjdk --candidate sudo snap install openjdk --beta sudo snap install openjdk --edge
You may have to slightly modify the update-alternatives commands when using one of these alternative builds. We used /snap/openjdk/current/ in our update-alternatives commands. Check if a different folder like “edge” is being used (just ls /snap/openjdk and see what’s in there)!
If you’re trying to set up SSD / USB storage booting check out my Raspberry Pi USB booting setup guide
To find out where to get the 64 bit version of Raspberry Pi OS view Where to get the 64 bit Raspberry Pi OS image
For benchmarks and recommendations on the fastest storage drives/adapters for the Raspberry Pi check out my 2021 Storage Roundup
If you’re having firmware issues and need to update/restore your firmware: Raspberry Pi firmware guide here
For my new overclocking and SSD setup guide for the Pi 400 check out my Pi 400 Overclocking and SSD setup guide