While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.
I got new MacBook Air M1 recently and first thing I wanted to install there was Java. So, I downloaded OpenJDK tar file, extracted it and tried to run “java -version” command and it threw the error:
-bash: ./java: Bad CPU type in executable
This was something new to me, I have worked on Java and Mac OS for so long and never saw this kind of error. After some online searches and debugging, I found that it’s happening because new MacBook M1 chip is using ARM64 architecture and OpenJDK binaries downloaded from the JDK site is built for x64 architecture, which is used by Intel processors.
After the issue was identified, the solution was simple. All I needed was to find an OpenJDK implementation that supports ARM64 architecture. After some searches, I landed on the Azul Zulu OpenJDK builds page and it had the ARM 64-bit architecture build.
I downloaded the tar file, extracted it and run the java command and it worked fine.
$ curl -O https://cdn.azul.com/zulu/bin/zulu16.30.19-ca-jdk16.0.1-macosx_aarch64.tar.gz $ tar -xvf zulu16.30.19-ca-jdk16.0.1-macosx_aarch64.tar.gz $ cd zulu16.30.19-ca-jdk16.0.1-macosx_aarch64/bin $ ./java -version openjdk version "16.0.1" 2021-04-20 OpenJDK Runtime Environment Zulu16.30+19-CA (build 16.0.1+9) OpenJDK 64-Bit Server VM Zulu16.30+19-CA (build 16.0.1+9, mixed mode) $
This was the first experience of “Bad CPU type in executable” for me. But, if you are here then it means you are facing this too. It could be Java or any other software. The solution is to find the ARM 64-bit architecture based build of the software and you should be fine.
After I was done with my Java setup, I came to know that we can also install “Rosetta 2”. This tiny utility runs in the background and allows us to run software that is built for Intel x64 architecture in Apple chips Macs. Read more at this Apple Support thread.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.