Report this

What is the reason for this report?

[Fixed] Bad CPU type in executable - Installing Java on MacBook

Published on August 4, 2022
[Fixed] Bad CPU type in executable - Installing Java on MacBook

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.

Fix for -bash: ./java: Bad CPU type in executable

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)
$

Conclusion

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.

Rosetta 2

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.

Learn more about our products

About the author

Pankaj Kumar
Pankaj Kumar
Author
See author profile

Java and Python Developer for 20+ years, Open Source Enthusiast, Founder of https://www.askpython.com/, https://www.linuxfordevices.com/, and JournalDev.com (acquired by DigitalOcean). Passionate about writing technical articles and sharing knowledge with others. Love Java, Python, Unix and related technologies. Follow my X @PankajWebDev

Category:
Tags:
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.

Still looking for an answer?

Was this helpful?
Creative CommonsThis work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.
Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.