How to Install any Java version on Raspberry Pi?

1. Download the Java version you want to install from the Oracle website.

2. Extract the downloaded file to a directory on your Raspberry Pi.

3. Open a terminal window and navigate to the directory where you extracted the Java version.

4. Run the following command to install the Java version:

sudo apt-get install openjdk-

Replace with the version of Java you downloaded.

5. Once the installation is complete, you can verify the installation by running the following command:

java -version

This should display the version of Java you installed.

Java on Raspberry Pi, and generally on Linux, is a nightmare.
As on Windows, there are many versions, different packages for users or developers. And on Linux, you can also add the proprietary topic as Java is now owned by Oracle.
I know that many of you have issues with Java on Raspberry Pi, and I will try to help you here 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 “openjdk-11-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.
Feel free to use the content table below if you already know the basics.

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 with 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.

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 version history :

Version Release date
Java 8 March 2014
Java 9 September 2017
Java 10 March 2018
Java 11 September 2018
Java 12 March 2019
Java 13 September 2019
Java 14 March 2020

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

You should also understand that developers are not following the same rhythm.
So, even if you install Java 14 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

During writing, the following versions are available in the Raspberry Pi OS repository:

  • openjdk-8-jre and openjdk-8-jdk
  • openjdk-9-jre andopenjdk-9-jdk
  • openjdk-10-jre andopenjdk-10-jdk
  • openjdk-11-jre andopenjdk-11-jdk

If any of them is OK for you, follow the next steps.

Raspberry Pi OS Desktop

As I wrote in introduction, the full version of Raspberry Pi OS Desktop has already the latest Java version installed (version 11).
If you are on Raspberry Pi OS Desktop “basic” or if you want to use another 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”, look directly for the list I gave you previously.
    So for example, enter “openjdk-11-jdk” in the search engine
  • Then check the corresponding package in the results
  • 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 ?

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: https://jdk.java.net/.
      Choose the version you want and download the corresponding file (the page layout is not always the same)
      For example, with JDK version 12 :
      wget https://download.java.net/openjdk/jdk12/ri/openjdk-12+32_src.zip
    • Another way is to go directly to the source code available here: http://hg.openjdk.java.net/jdk-updates.
      Then you can choose a version and download the zip file from the left menu, or clone it on your Raspberry Pi
  • 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

Installation

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

  • Extract the files from the archive
    unzip openjdk-12+32_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
  • Install the most recent JDK version available (if not already installed):
    sudo apt install openjdk-11-jdk
    Installing JDK 14 is not possible directly on Raspberry Pi OS Buster.
    Except if you are repeating the same thing for each missing version :/
  • 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:
    make
  • And 20 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

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.

Update Java to another version on Raspberry Pi

Remove & install

You may have this notification on Windows where Java asks for an update regularly, but there is no direct way to update Java on 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-9-jdk
sudo apt install openjdk-11-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.

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.

Conclusion

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.

How to Install any Java Version on Raspberry Pi

Installing Java on your Raspberry Pi is a great way to get the most out of your device. Java is a powerful programming language that can be used to create a wide variety of applications. With the right setup, you can use Java to create powerful applications for your Raspberry Pi.

Step 1: Download the Java Version

The first step is to download the version of Java that you want to install. You can find the latest version of Java on the Oracle website. Once you have downloaded the version of Java that you want to install, you can move on to the next step.

Step 2: Install Java

Once you have downloaded the version of Java that you want to install, you can use the command line to install it. To do this, open a terminal window and type the following command:

sudo apt-get install openjdk-<version>

Replace <version> with the version of Java that you downloaded. This will install the version of Java that you downloaded. Once the installation is complete, you can move on to the next step.

Step 3: Set the Default Java Version

Once you have installed the version of Java that you want to use, you can set it as the default version. To do this, type the following command in the terminal window:

sudo update-alternatives --config java

This will open a list of all the versions of Java that are installed on your Raspberry Pi. Select the version of Java that you want to use and press enter. This will set the version of Java that you selected as the default version.

Step 4: Test the Installation

Once you have installed and set the default version of Java, you can test the installation. To do this, type the following command in the terminal window:

java -version

This will display the version of Java that is currently installed. If the version displayed is the version that you installed, then the installation was successful.

Conclusion

Installing Java on your Raspberry Pi is a great way to get the most out of your device. With the right setup, you can use Java to create powerful applications for your Raspberry Pi. Follow the steps outlined in this article to install and set the default version of Java on your Raspberry Pi.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?