6

I am trying to install OpenJDK 16 on my Raspberry Pi 4. I'm running a minecraft server and there was an update recently which requires Java 16, but I have Java 8 installed. There is no openjdk-16-jdk package so I downloaded the tar file for Linux / AArch64 as the Pi has an ARM processor. I then followed these instructions to install it. When I try to run java -version, I get this error:

bash: /usr/bin/java: cannot execute binary file: Exec format error

It appears this is the wrong version, but neither of the Linux downloads on the website worked, so I'm not sure what is wrong. Here's a bit of system information in case it's useful:
Linux raspberrypi 5.10.17-v7l+ #1403 SMP Mon Feb 22 11:33:35 GMT 2021 armv7l GNU/Linux
And these are the options for sudo update-alternatives --config java:

Selection    Path                                             Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-1.16.0-openjdk-armhf/bin/java   1131      auto mode
* 1            /usr/lib/jvm/java-1.16.0-openjdk-armhf/bin/java   1131      manual mode
  2            /usr/lib/jvm/java-1.8.0-openjdk-armhf/bin/java    1131      manual mode
  3            /usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java    1081      manual mode
2
  • 1
    AArch64 is 64-bit, your kernel is armv7l which is 32-bit. You cannot run 64-bit userspace applications using a 32-bit operating system. You'll either have to upgrade to a 64-bit OS, or find a 32-bit version of Java.
    – tttapa
    Jun 8, 2021 at 20:34
  • @tttapa Thank you, unfortunately it looks like all the downloads are 64 bit
    – Henry
    Jun 8, 2021 at 20:49

3 Answers 3

8

I wrestled with the same issue a few days ago.

I have been running a Minecraft server on a Raspberry Pi 4, using Java 8, installed via sudo apt install openjdk-8-jdk.

However, as of snapshot 21w19a, which was a few snapshots before the 1.17 release, Java 16 has become the minimum for Minecraft.

The Java 16 binary in the openjdk-16.0.1_linux-aarch64_bin.tar.gz file I downloaded from http://jdk.java.net/16/ gives an error when run on my Raspberry Pi 4:

$ ./jdk-16.0.1/bin/java --version
-bash: ./jdk-16.0.1/bin/java: cannot execute binary file: Exec format error

If we use file on that binary, we can see a bit more detail:

$ file ./jdk-16.0.1/bin/java
./jdk-16.0.1/bin/java: ELF 64-bit LSB shared object, ARM aarch64,
version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1,
for GNU/Linux 3.7.0, not stripped

Note "64-bit" and "ARM aarch64".

Compare this with the working Java 8 binary I have - note "32-bit" here:

$ file /usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java
/usr/lib/jvm/java-8-openjdk-armhf/jre/bin/java: ELF 32-bit LSB executable, ARM,
EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3,
for GNU/Linux 3.2.0, BuildID[sha1]=6d2781f51a497603976e8fee28b888bd771fd5b7, stripped

I believe (I'm no expert) that the Raspberry Pi 4 CPU is able to run aarch64 code, but the current default OS doesn't support it.

$ uname -a
Linux [name] 5.10.17-v7l+ #1414 SMP Fri Apr 30 13:20:47 BST 2021 armv7l GNU/Linux

There, note armv7l.

This article - "How to Make Your Raspberry Pi 4 Faster with a 64 Bit Kernel" helped me to understand a little more. If I read that right, although we could edit /boot/config.txt to include the arm_64bit=1, that would give us a 64 bit kernel, but not the ability to run 64 bit aarch64 binaries, because we still have a 32 bit userland. (If I've misunderstood here, I'd appreciate if someone could correct me so I can learn.)

So, summary so far: Oracle supply a Java 16 JDK at jdk.java.net, but the only ARM binary there is aarch64. I think this may be supported by the processor on the Raspberry Pi 4, but not by the default OS.

Luckily, AdoptOpenJDK (run by a community of Java User Group members, including some big names) seem to make a wider variety of Java binaries available for download.

I went to https://adoptopenjdk.net/releases.html and made the following choices:

  • Version: OpenJDK 16 (Latest)

    • Chose because Java 16 is the minimum for Minecraft 1.17 (see top of post).
    • Note this isn't a "Long Term Support" (LTS) version. This Minecraft Paper server post about Java 16 explains more.
  • JVM: HotSpot

    • The alternative option here is OpenJ9, but I believe that Mojang ship and test Minecraft with the HotSpot JVM, so that's what I chose.
  • Operating System: Linux

  • Architecture: arm32

    • Not aarch64: see above
  • JDK or JRE: JRE

    • To run Minecraft, all we need is a java binary. So the Java Runtime Environment (JRE) is fine. The Java Development Kit (JDK) includes more tools, but the JRE is a smaller download and installation, so I went for that. See this question for more on JDK vs JRE.

Those choices have given me a working Java 16:

$ ./jdk-16.0.1+9-jre/bin/java -version
openjdk version "16.0.1" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-16.0.1+9 (build 16.0.1+9)
OpenJDK Server VM AdoptOpenJDK-16.0.1+9 (build 16.0.1+9, mixed mode)
$ file ./jdk-16.0.1+9-jre/bin/java
./jdk-16.0.1+9-jre/bin/java: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV),
dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0,
not stripped

... and this is working so far for me, in the limited testing I've done so far, with the vanilla 1.17 server JAR I downloaded from https://www.minecraft.net/en-us/download/server.

5
  • Thanks for your answer. Unlike mine it actually explains the process well so I've accepted it.
    – Henry
    Jun 16, 2021 at 11:34
  • 1
    Thanks @Henry! It's not a perfect answer - there's still much here that I don't understand. Perhaps someone will improve it. I thought your question was well written, by the way.
    – Ashley
    Jun 16, 2021 at 15:56
  • 4
    Great answer @Ashley I just wanted to point out that, after download the tar gz file, you will need to extract it and bind the folder in the PATH environment variable with export PATH=$PWD/jdk-16.0.1+9-jre/bin:$PATH Jun 19, 2021 at 14:38
  • the new link from where to download openjdk is here you would need 17.x for minecraft 1.18 and newer Dec 11, 2021 at 1:48
  • Great answer - I messed around with apt for about 4 hours before I found this. In a few minutes, I was up running. May 4 at 20:50
1

I did the following and it worked for me (To install openjdk 16 for minecraft 1.17.1):

First I downloaded any jdk by using:

sudo apt install openjdk-8-jdk

Then I downloaded this file and extracted it in a new folder under /usr/lib/jvm

After that I runned:

sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/{name of the folder you just created}/bin/java 1131

And then I checked it was installed and selected by using:

sudo update-alternatives --config java
0

Because the JDK was 64-bit and the Pi is 32-bit, I had to get a 64-bit terminal by following this guide and doing the following:

  1. sudo apt-get update and sudo apt-get -y upgrade to make sure everything is up to date
  2. sudo apt-get install -y --no-install-recommends raspbian-nspawn-64 to install the 64-bit Debian Buster terminal
  3. ds64-shell to launch the 64-bit shell
  4. I used this SO answer to install java 8 in the 64-bit shell. From there I followed the same procedure as before to install java 16 and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.