error Attempting to install Java on a MacBook.

After recently purchasing a new MacBook Air M1, the first thing I aimed to do was install Java. Consequently, I downloaded the OpenJDK tar file, extracted it, and attempted to execute the command “java -version,” only to encounter an error.

The executable file “./java” is encountering an error due to an incompatible CPU type.

I had never encountered this type of error before, as I have been working with Java and Mac OS for a long time. However, after conducting online searches and debugging, I discovered that the issue arises due to the new MacBook M1 chip’s utilization of the ARM64 architecture, while the downloaded OpenJDK binaries from the JDK site are designed for x64 architecture typically used by Intel processors.

The solution to the error message “-bash: ./java: Bad CPU type in executable” needs to be applied.

Once the problem was recognized, solving it became effortless. All I had to do was locate an OpenJDK version compatible with ARM64 architecture. After conducting a few searches, I stumbled upon the Azul Zulu OpenJDK builds page, which provided the ARM 64-bit architecture build I needed.

I successfully downloaded the tar file, extracted it, ran the java command, and had no issues.

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

In summary

I had never encountered the “Bad CPU type in executable” issue before, but if you’re here, it probably means you’re dealing with it too. Whether it’s Java or any other program, all you need to do is locate the appropriate ARM 64-bit architecture version of the software, and everything should work smoothly.

One possible paraphrase of “Rosetta 2” is “Rosetta Two.”

Once my Java setup was complete, I discovered the possibility of installing “Rosetta 2” as well. This small tool operates silently and enables the execution of software designed for Intel x64 architecture on Macs powered by Apple chips. For further information, refer to this Apple Support discussion.

 

More tutorials

Python Compiler Error during package installation?(Opens in a new browser tab)

Common errors that occur when using Nginx for connections.(Opens in a new browser tab)

A native guide to the atop command in Linux(Opens in a new browser tab)

automatic scaling of Kubernetes pods using Metrics Server?(Opens in a new browser tab)

Addition Assignment Operator mean in Java(Opens in a new browser tab)

 

Leave a Reply 0

Your email address will not be published. Required fields are marked *