install java raspberry pi

How to Install Any Java Version on a Raspberry Pi

Java on Raspberry Pi, and Linux in general, is a nightmare. Like on Windows, there are many versions and 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

Java is not as simple as we might think, so I’ll start with a quick reminder on different concepts you need to understand before going any further.

What is Java?

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

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

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.

Join Our Community!

Connect, learn, and grow with other Raspberry Pi enthusiasts. Support RaspberryTips and enjoy an ad-free reading experience. Get exclusive monthly video tutorials and many other benefits.

Learn more

Java has been created by Sun Microsystems and licensed under the GNU GPL. So, it was crystal clear.
But in 2009, Oracle bought Sun and, so, Java.
Oracle’s 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 still available under GNU GPL, but the Oracle version is now a commercial product, free for personal use, but a paid service for commercial use.
You can learn more here if you are interested.

You will probably need more information to understand the story, but for now, just remember that it’s complicated and you have two different products available.

On Raspberry Pi, you’ll find that you 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 languages, there are regularly new versions available.

Java is updated to a new major version almost every 6 months.

Here is a summary of the Java version 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 do not follow the same rhythm.
So, even if you install Java 17 now on your Raspberry Pi, some programs may not work with it or aren’t optimized for this version.

Most of the time, the version from the Raspberry Pi OS repository will be perfect with 99% of your software. If you have an issue with something, you can check the editor recommendations to see which one you need. Sometimes 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, 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 installation. 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 website.

Use the package manager

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

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

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

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

Raspberry Pi OS Desktop

As mentioned in the introduction, the full version of Raspberry Pi OS Desktop already has the latest version of Java 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 searches 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 an 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 directly install 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 minutes, Java is installed and ready to use.
You can get the exact version and check that everything works 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 they do not work on Raspberry Pi. So, your only option is to find the source files for the version you need.

I prefer to warn you that 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: https://jdk.java.net/.
      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:
      wget https://download.java.net/openjdk/jdk18/ri/openjdk-18+36_src.zip
  • 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 can add the information here.

Installation

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), and 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:
    unzip openjdk-18+36_src.zip
  • 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

    You might get an error, usually 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 won’t get too many errors.
  • Finally, it’s a success for me, everything is ok:
  • You can now build it with:
    make
  • 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 the 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.

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!

Reminder: Remember that all the members of my community get access to this website without ads, exclusive courses and much more. You can become part of this community for as little as $5 per month & get all the benefits immediately.

Conclusion

That’s it, you now know many things about Java, 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.

Similar Posts

One Comment

Comments are closed.