How to migrate Homebrew from Intel chip installation to Apple Silicon
- 4 minutes read - 644 wordsI have been using an Apple M1 laptop since autumn of 2021, but I just recently came across an issue that surprised me. It seems I hadn’t converted Homebrew (a package manager for macOS) for compatibility with Apple Silicon. I mostly use Homebrew to install packages I rarely use (such as Ruby or Python libraries), so perhaps that’s why I hadn’t noticed. However, this issue surfaced because I tried to install a Python package (Poetry) to work on a generative AI project, and it was looking for Python in the wrong place.
After diving down some rabbit holes to determine the actual root of the problem, I was able to migrate Homebrew for Apple Silicon. Here’s how I did it.
The problem
First, I tried to install Poetry using the official installer (per the documentation instructions):
curl -sSL https://install.python-poetry.org | python3 -
That produced the following error:
dyld[69425]: Library not loaded: @loader_path/../Python
Referenced from: <DAED6A8B-509E-3042-B1F9-2F792191741A> /Users/jenniferreif/Library/Application Support/pypoetry/venv/bin/python3.11
Reason: tried: '/Users/jenniferreif/Library/Application Support/pypoetry/venv/bin/../Python' (no such file), '/usr/local/lib/Python' (no such file), '/usr/lib/Python' (no such file, not in dyld cache)
Traceback:
File "<stdin>", line 923, in main
File "<stdin>", line 562, in run
Hm, so looks like it can’t find Python. Next, I ran a command to ensure I had Python installed:
jenniferreif@elf-lord ~ % python3 --version
Python 3.11.4
jenniferreif@elf-lord ~ % which python3
/usr/local/bin/python3
jenniferreif@elf-lord ~ % which python
python not found
Python shows up in /usr/local/bin
, but that doesn’t look like that’s where Poetry is looking for it. After a quick web search, many people found this to be a problem when they upgraded brew packages, so uninstalling and reinstalling Poetry seemed to fix it. However, I checked whether I had an existing Poetry installation (poetry --version
), and I did not. After a bit of digging, I also confirmed that Homebrew typically installs packages in the /usr/local/bin
, so Homebrew is likely the culprit.
Next, I thought I had better update Homebrew to the latest version, so I ran brew update
. That ran well, so I figured I’d better try to upgrade in case of a newer release, since it had been awhile. That’s where I ran into another error:
Error: Cannot install under Rosetta 2 in ARM default prefix (/opt/homebrew)!
To rerun under ARM use:
arch -arm64 brew install ...
To install under x86_64, install Homebrew into /usr/local.
Ok, so it looks like this might be the root problem, and this needs fixed before I can fix the problem with Poetry. I tried to run the suggested command under ARM use, but it needs an argument after the "install" keyword, so I did some research first on the error.
Many solutions were from 2022 or early 2023 saying that Homebrew didn’t yet fully support the ARM architecture. The solutions recommended using the arch -arm64
prefix for every command, but I wanted to first verify that Homebrew doesn’t still include ARM. I went to Homebrew’s website and did a search for "silicon" on their docs. According to their Installation docs, they do!
Now, since I had an existing Homebrew installation from my Intel machine that had been transferred to my M1 machine, I needed to migrate it to the new architecture. I found a couple of extremely helpful blog posts that explained how to do this, so I combined some of the details of each. I’ll list the steps next.
The solution
This first blog post came from the perspective of having both the Intel laptop and M1 laptop side-by-side and installing on the M1 from a clean slate. Since I don’t have the old laptop, I mainly used steps from this second blog post that explained how to migrate an existing installation.
Run
brew bundle dump
to create a Brewfile containing the list of all your existing Homebrew-installed packages.Run the following command to install Homebrew in the
/opt/homebrew
directory:/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Per blog post 1 (under the "Install Homebrew" section), follow your output of the previous command to add the Homebrew directory to your PATH. Because Homebrew is installed in a new location, it needs to know where to look. The commands should look something like those shown in my output below:
==> Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
(echo; echo 'eval "$(/usr/local/bin/brew shellenv)"') >> /Users/jenniferreif/.zprofile
eval "$(/usr/local/bin/brew shellenv)"
- Run brew help to get started
- Further documentation:
https://docs.brew.sh
Run
brew bundle install
to install all your packages from the Brewfile.
And that’s it!
Back where I began
In case you might be wondering if I ever got Poetry installed, I did! Running the Poetry install right after the brew change didn’t immediately solve it, but I ran brew update
and then brew upgrade
to ensure I had all the latest in Homebrew. Then I ran the following command to install Poetry:
curl -sSL https://install.python-poetry.org | python3 -
Next, I had to follow the output instructions to add Poetry to my PATH. I added the following to my shell profile:
export PATH="<path specified in output>:$PATH"
Finally, I ran poetry --version
to verify that it was installed!
Note: I could’ve also installed Poetry using Homebrew, but Poetry says that installation is not supported, so I figured I’d try to get the official installer to work first.
Wrap up
In this post, I walked through my process of migrating Homebrew from an Intel installation to an Apple Silicon installation. I also ran into an issue with installing the Poetry Python package, which I was able to resolve after migrating Homebrew. I hope this helps you if you run into a similar issue!
Resources
Blog post: Migrate Brew from Intel to M1 Mac
Blog post: Using Homebrew on M1 Mac
Website: Homebrew