Skip to content

Instantly share code, notes, and snippets.

@jtzero
Last active July 26, 2023 15:24
Show Gist options
  • Save jtzero/c956071d5bdca86865a60cc0a828c5f0 to your computer and use it in GitHub Desktop.
Save jtzero/c956071d5bdca86865a60cc0a828c5f0 to your computer and use it in GitHub Desktop.
x86 brew on mac m1
1. Set terminal to rosetta
If Rosetta 2 is not installed by default in your M1 Mac, then open the pre-installed Terminal app and run the following command: `/usr/sbin/softwareupdate --install-rosetta --agree-to-license`
Rosetta allows us to use apps built for Mac with intel chip.
Several CLI tools do not have native versions built for the new M1 architecture.
Enabling them on your native M1 Mac terminal can be frustrating.
Follow these steps to enable Rosetta:
- Select the app(Terminal) in the Finder.
- Right click on the app(Terminal) and select Get Info.
- In General, check the Open using Rosetta check-box.
- Close the Terminal Info.
- Now when you quit the terminal and open it again.
- If you haven't installed Rosetta yet, then it would prompt you to install it.
- If the popup shows up, then click on Install button, then enter your user name and password to allow installation to proceed.
- Close the Terminal and open again.
Now we have a special terminal that can install tools with Rosetta translation.
To verify that you are using a Rosetta terminal, run the following command and it should NOT output : `arm`
2. type `which brew` if it returns `/opt/homebrew` uninstall m1 homebrew a la `rm -rf /opt/homebrew` and then type which brew
3. Execute the following
```
cd /usr/local
sudo mkdir homebrew
sudo chown :staff homebrew
sudo chmod g+w homebrew
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
```
4. update you ~/.zshrc to have the following
```
if [ "$(uname -m)" = "x86_64" ]; then
alias brew="arch -x86_64 /usr/local/homebrew/bin/brew"
export HOMEBREW_CELLAR="/usr/local/Cellar" #needed?
export BROW="/usr/local/homebrew"
export LDFLAGS="-L${BROW}/opt/openssl@1.1/lib -L${BROW}/opt/readline/lib -L${BROW}/opt/xz/lib"
export CPPFLAGS="-I${BROW}/opt/openssl@1.1/include -I${BROW}/opt/readline/include -I${BROW}/opt/xz/include"
export PATH="${BROW}/bin:$PATH"
export ARCHPREFERENCE="x86_64"
alias asdf="arch asdf"
else
if [ ! -f /opt/homebrew/bin/brew ]; then
echo "m1 Homebrew cannot be found" >&2
else
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
fi
```
5. restart your terminal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment