install java raspberry pi

How to Install Any Java Version on Raspberry Pi?

Java on Raspberry Pi, and Linux in general, is a nightmare. Like on Windows, there are many versions, different packages for users or developers. And on Linux, you can add the proprietary issue, as Java is now owned by Oracle. I know that many of you have problems with Java on Raspberry Pi, and I will try to help you with this tutorial.

Java is already installed by default on Raspberry Pi OS Full, so there is nothing to do.
To install Java on another version (Desktop or Lite), the package “default-jre” has to be installed with apt or the “Add / Remove software” tool.

So, the quick answer is simple, but let’s get into a little more detail now.

If you’re looking to quickly progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.

Introduction about Java

As Java is not as simple as we might think, I start with a quick reminder about different concepts you need to understand before going further.

What is Java?

Ok, so first point, Java is a popular programming language.
You’ll find it almost everywhere, and even it’s an old school language (created in 1995), it’s still very common to use it.

What developers like about Java is its portability. It’s working on about any platform without recompilation. It’s also a strong language with a huge community, so you can find help easily on Stack Overflow for example.

So, even if Raspberry Pi is mainly known for Python programming, you can absolutely use it to learn Java or code something with it.
You may also need Java to run some software built with it.

Is Java open-source?

This one is a controversial point 🙂
The short answer is that Java is free and open-source.

Java has been created by Sun Microsystems and licensed under the GNU GPL. So, it was crystal clear.
But in 2009, Oracle has bought Sun and so Java.
Oracle main market is the companies, and it was not good news for Java developers.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

Currently, there are two Java versions available : Java SE and OpenJDK.
OpenJDK is till available under GNU GPL, but the Oracle version is now a commercial product, free for a personal use but a paid service for a commercial use.
You can learn more here if you are interested.

You will probably need more information to understand all the story, but for now just remember that it’s complicated and you have two different products available.
On Raspberry Pi, you’ll find only have access to the OpenJDK version. There is no release or sources available for the ARM architecture for the commercial version.

Java versions

This one is easier. As with most software and programming language, there are regularly new versions available
Java was updated to a new major version almost every 6 months recently.

Here is a summary of the Java versions history :

VersionRelease date
Java 14March 2020
Java 15September 2020
Java 16March 2021
Java 17September 2021
Java 18March 2022
Java 19September 2022
Java 20March 2023
Java 21September 2023

As always with Debian / Raspberry Pi OS, recent versions are not available in the repository.
Currently, Raspberry Pi OS Bookworm includes OpenJDK17 (and a few older versions).

You should also understand that developers are not following the same rhythm.
So, even if you install Java 17 now on your Raspberry Pi, some programs may not work with it, or not be optimized for this version.

Most of the time, the version from the Raspberry Pi OS repository will be perfect with 99% of your software.
And if you have an issue with something, you can check the editor recommendations to see which one you need
Sometime you will need to downgrade Java to use a specific version.

Java packages

We are almost done with the theory about Java.
One last thing I want to clarify is the “JDK” thing.
Java developers use initials everywhere, and it’s not always easy to understand as a beginner.

Here is a list of initials you can find in the “Java world”:

  • JRE: Java Runtime Environment
    It’s the only thing you need if you are not a developer. It allows you to run Java software on your device
  • JDK: Java Developer Kit
    As the name suggests, it’s required for developers
    It includes the compiler, launcher and other required tools
  • JVM: Java Virtual Machine
    It’s a part of JRE, but you can also download it separately.
    It provides a runtime environment to drive Java applications

So, basically, you need to install JRE to only run Java applications, or JDK if you want to create them.

Install Java on a Raspberry Pi

Now that you understand all the concepts, we can move to the installation part.
I will show you how to install Java with the package manager or from the website.
Most of the time the package manager will be perfect, but if you need a specific version, you can check the last part.

Use the package manager

At any time, you may find different versions available via the package manager:

In a command line, you can try this to see all JRE versions available directly via APT:
apt search openjdk-[0-9]+-jre

If any of them is OK for you, follow the next steps to install it on your Raspberry Pi.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

Raspberry Pi OS Desktop

As mentioned in the introduction, the full version of Raspberry Pi OS Desktop has already the latest Java version installed.
If you use another system version, or want to use a specific version instead, follow these steps:

  • In the main menu, go to Preferences > Add / Remove Software
  • Then use the search engine to find the package to install.
    As you will get many answers for search like “java” or “openjdk”, I recommend looking for a specific version instead.
    So, for example, enter “openjdk-17-jdk” in the search engine
  • Then check the corresponding package in the results

    Same for JRE if you need it too.
  • Click “Apply” to install it
  • Enter your password to confirm
  • And then Ok to exit

If it doesn’t work, try to update the packages lists:
Options > Refresh packages lists.
This tool doesn’t display any error if the package is unavailable :/

After a few minutes, Java is installed and ready to use.
You can do a quick check to verify that everything is OK by starting a terminal and typing:
java -version

And you can also use Geany or any other IDE to compile & run your first program 🙂

Are you a bit lost in the Linux command line? Check this article first for the most important commands to remember and a free downloadable cheat sheet so you can have the commands at your fingertips.

Raspberry Pi OS Lite

On Raspberry Pi OS Lite, Java is not available by default, so you can install directly the version you need.

  • Start by updating the repository information to avoid any error in the installation:
    sudo apt update
  • Then install the needed package.
    For example, if you want the Java 11 JRE :
    sudo apt install openjdk-11-jre
    Raspberry Pi OS needs to install many dependencies (119 in my case!).
  • Confirm with “Y”

After a few minute Java is installed and ready to use.
You can get the exact version and check that everything work with:
java -version

Then you can run any program with “java -jar”.
For example, if your goal is to run a Minecraft Server:
java -jar spigot-xx.jar

Install another Java version

If you want to install another version, not available in the repository, you need to download it from the OpenJDK website.
On the website, there are some Linux packages available, but there are not working on Raspberry Pi.
So, your only option is to find the sources files for the version you need.

I prefer to warn you directly, you’ll probably need at least one hour to try this, and there is no guarantee to succeed, so I hope you have an excellent reason to try it 🙂

Links & download

  • OpenJDK
    • OpenJDK builds for all versions are available here:
      Choose the version you want in the left menu and download the corresponding file (the page layout is not always the same).
      Then use the wget command to download the file to your Raspberry Pi :
      wget <url>
      Make sure to download the source code, binaries won’t work on Raspberry Pi. For example:
  • Oracle
    • Oracle sources seem to be only available for x64 architectures, so it probably doesn’t work on Raspberry Pi. If I have missed something, let me know in the community, so I could add the information here


Note: You can’t upgrade from, let’s say, version 17 to 21 in one installation. You need to first install the latest version available in the repository (17 currently), install 18 manually. And then repeat the same steps for each version.

Here is how to compile Java from the sources to get a newer or older version:

  • Extract the files from the archive
  • Install the required packages if needed:
    sudo apt install autoconf build-essential libcups2-dev libx11-dev libasound2-dev libxext-dev libfontconfig1-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev zip
  • You also need to make sure you have the previous version installed, for example:
    sudo apt install openjdk-17-jdk
  • Then start the configuration step:
    cd openjdk
    bash configure

    If you have any error, most of the time it will ask you to install a missing package.
    Do it and start again.
    But I have listed previously everything it asks me to add, so I hope you’ll not get too many errors 🙂
  • Finally, it’s a success for me, everything is ok:
  • You can now build it with:
  • A few minutes later, get your binaries in the subfolder build/linux-arm-server-release/jdk/bin.
    You can now use the java to run any code with this specific version:
    ./build/linux-arm-server-release/jdk/bin/java --version
Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

Update Java to another version on Raspberry Pi

Remove & install

You may know this notification on Windows where Java asks for an update regularly, but there is no direct way to update Java on the Raspberry Pi.

The easiest solution is to uninstall your current version and install the latest available.
So, on Raspberry Pi OS Desktop, uncheck the box in Add / Remove software and check the one you want to install.

On Raspberry Pi OS Lite, you can use apt to do the same thing, for example:
sudo apt remove openjdk-16-jdk
sudo apt install openjdk-17-jdk

And finally, if you installed your version from sources, remember that the previous JDK version is needed to build a new one.
So don’t remove the current one before building it.

🖋 Love Raspberry Pi & writing?
Combine your passions and get paid. Write for RaspberryTips!

Keeping several versions

You can keep both if you want, but if it’s not mandatory, it may be more of a problem than anything (for example, some software might continue to use the older version).

On Raspberry Pi OS Desktop there is a great tool to switch easily between versions: G Alternatives.
You can find it in the Add / remove software tool, look for “galternatives” in the search engine.

Once installed, it’s available in the main menu > Preferences > Alternatives Configurator
It looks like this:

Then you can check the version you want to use and this version will be used by default by all the applications.

Download Your Essential Linux Commands Guide!
It's a free PDF guide containing every Raspberry Pi Linux command you should know!
Download now

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Want to chat with other Raspberry Pi enthusiasts? Join the community, share your current projects and ask for help directly in the forums.


That’s it, you now know many things about Java and especially how to install and update it on Raspberry Pi.

If you had issues with Java, I hope this post was useful for you.

Whenever you’re ready, here are other ways I can help you:

The RaspberryTips Community: If you want to hang out with me and other Raspberry Pi fans, you can join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.

Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.

The Raspberry Pi Bootcamp: Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.

Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.

You can also find all my recommendations for tools and hardware on this page.

Sharing is caring!

Similar Posts

One Comment

Comments are closed.