Tutorial

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

Published on August 4, 2022
author

Pankaj

[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 authors
Default avatar
Pankaj

author

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?

Ask a questionSearch for more help

Was this helpful?
 

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

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.