Java Installation on MacBook M1 without ‘Bad CPU type’ Error

Encountering the ‘Bad CPU type in executable’ error during Java installation on your MacBook Air M1? We’ll show you how to effortlessly resolve this issue.

Common Error

Due to the ARM64 architecture of Apple’s new M1 chip, you might receive this error message when attempting to run the command “java -version”:

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

The issue arises because the downloaded OpenJDK binary files are designed for the x64 architecture – an architecture commonly used in Intel processors, and thus not compatible with the new M1 chip.

Solution: Find an ARM64-Compatible OpenJDK Version

To solve the problem, you need to use an OpenJDK version that is compatible with the ARM 64-bit architecture. We recommend Azul Zulu OpenJDK builds, which also provide builds for the ARM 64-bit architecture.

After downloading and extracting the appropriate Tar archive, you can run the Java command without any problems:

 $ 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

The result should now read as follows:

 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)

Additional Note: Rosetta 2

After successfully installing Java, “Rosetta 2” runs in the background. This small application enables the execution of software originally developed for the Intel x64 architecture on Apple chip Macs. For more information, please refer to the Apple Support thread.

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in:

centron Managed Cloud Hosting in Deutschland

Mocking Void Methods with EasyMock

Guide, JavaScript
Mocking Void Methods with EasyMock In unit testing, mocking is an essential technique that allows developers to simulate the behavior of complex objects. EasyMock is a popular framework for creating…