After trying to install Homebrew on a new MacBook Pro 13" 2020, the mentioned error exception appeared on the terminal. In this article, I'm going to explain to you how to solve this problem and continue with your workflow as usual.
Install through Rosetta 2
The new Macs with M1 chip use the arm64 CPU architecture, the same that recent iOS devices use (Intel-based Macs use an architecture called x86-64). This by itself means that the apps that were developed to run on iOS and iPadOS, will run as well on macOS. This means however that apps that were developed for Intel's architecture won't run natively on the new Apple's hardware (exactly what's happening with Homebrew).
That's where the Rosetta 2 emulator comes in. It's an emulator built into macOS Big Sur that allows ARM Macs to run the old intel applications. The emulator basically translated the instructions that were written for intel processors into commands that Apple's chip will understand. As a developer you won't need to make any changes to old apps, they will just work. In this case, to install Homebrew with this compatibility, run the installation command with the following prefix:
So the installation command for Homebrew will be the following instead:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
The command will run the default homebrew installer and set up it in the
/usr/local directory. So whenever you need to do something with brew again, you just need to put before
arch -x86_64 brew <your instruction>
And that's it! For example, if you would like to install a new package, the following command would do the trick:
arch -x86_64 brew install <package>
Of course, this is quite annoying, however, this won't happen forever, with some luck in the future the project will provide support for the new apple sillicon.
Happy coding ❤️!