Fork me on GitHub

Project Notes

#293 on Apple Silicon

Using Homebrew to manage ARM64 and x86_64 package installations on macOS.

Notes

With the introduction of the M1 (ARM) chip, Apple once again forced us all to swap underlying processor architecture (remember the Power PC, and 68k?). This is meant to be transparent for users, but it can be a bumpy ride for developers during the transitional years, as foundational packages and libraries all need to be updated.

I often use Homebrew to manage software installations on my Mac.

While it is possible to prepend arch --x86_64 to emulate Intel for any brew command, this will cause it to attempt to install a mix of packages for different architectures and probably won’t work.

The best option is obviously to avoid any x86_64 code at all. But if that is not possible, another alternative is to maintain two separate brew installations - one for each processor architecture.

Installing Parallel Brews

First install Homebrew for Apple Silicon at /opt/homebrew by default:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

A second Intel-emulated installation using the arch command will install to /usr/local by default:

arch --x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

NB: this required Rosetta 2 support to be enabled first; run softwareupdate --install-rosetta.

arch --x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
...
==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    (echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> /Users/paulgallagher/.bash_profile
    eval "$(/usr/local/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

Automatically selecting the correct brew

NB: this is for zsh only

Adding the following snippet to .zshrc will cause the appropriate Homebrew to be added to the path:

if [ "$(arch)" = "arm64" ]; then
    eval "$(/opt/homebrew/bin/brew shellenv)"
else
    eval "$(/usr/local/bin/brew shellenv)"
fi

Running a shell with default arm64 architecture:

$ zsh
% arch
arm64
% which brew
/opt/homebrew/bin/brew

Running a shell with x86_64 architecture:

$ arch --x86_64 zsh
Restored session: Wed Aug  7 11:08:46 +08 2024
% arch
i386
% which brew
/usr/local/bin/brew

Credits and References

About LCK#293 ToolsMacOS

This page is a web-friendly rendering of my project notes shared in the LittleCodingKata GitHub repository.

Project Source on GitHub Return to the LittleCodingKata Catalog
About LittleCodingKata

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.

Follow the Blog follow projects and notes as they are published in your favourite feed reader