48

I want to install and run two versions of Homebrew simultaneously on an Apple Silicon Mac: an ARM64 version, and an Intel version running under Rosetta 2.

I know I can prepend any brew command with arch --x86_64 to emulate Intel for that command, but this can lead to conflicts for formulas whose dependencies you already have built for ARM64. For example:

Error: gnupg dependencies not built for the x86_64 CPU architecture:
  pkg-config was built for arm64
  gettext was built for arm64
  readline was built for arm64
  openssl@1.1 was built for arm64

How can I install and run two separate, isolated versions of Homebrew (one for native ARM64 and one for emulated Intel), keeping each of their installed formulae and dependencies separate?

Jacob Ford
  • 4,553
  • 5
  • 27
  • 42

2 Answers2

105
  1. Install Homebrew natively on Apple Silicon (will install to /opt/homebrew by default):

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  2. Install Intel-emulated Homebrew (will install to /usr/local by default):

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

    If you haven't yet installed Rosetta 2, you'll need to run softwareupdate --install-rosetta first.

  3. Create an alias for Intel homebrew. I'm calling mine brow because O for old. But hey you do your own thing.

    In ~/.zshrc (or your shell's equivalent) add:

    alias brow='arch --x86_64 /usr/local/Homebrew/bin/brew'
    
  4. Add ARM Homebrew to your PATH.

    In ~/.zshrc (or your shell's equivalent) add:

    # Homebrew on Apple Silicon
    path=('/opt/homebrew/bin' $path)
    export PATH
    

    If you're still on bash it'd be PATH=/opt/homebrew/bin:$PATH

  5. Confirm

    which brew should return /opt/homebrew/bin/brew

    brew --prefix should return /opt/homebrew

    which brow should return brow: aliased to arch --x86_64 /usr/local/Homebrew/bin/brew

    brow --prefix should return /usr/local


If you have the same command installed in both Homebrews, it'll default to Apple Silicon (/opt/homebrew/) since we prepended that one in our PATH. To override, run the command with its full path (/usr/local/bin/youtube-dl), or override your PATH for one command (PATH=/usr/local/bin youtube-dl).

I also created another handy alias in .zshrc (alias ib='PATH=/usr/local/bin') so I can prepend any Homebrew-installed command with ib to force using the Intel version of that command:

~ ▶ which youtube-dl
/opt/homebrew/bin/youtube-dl
~ ▶ ib which youtube-dl
/usr/local/bin/youtube-dl

If you prefer Intel to be the default brew, add /opt/homebrew/bin to the end of your PATH instead of the beginning.

Jacob Ford
  • 4,553
  • 5
  • 27
  • 42
  • for some reason the `arch` command does not work for me ... :( ```bash $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" Password: Homebrew is not (yet) supported on ARM processors! [...] ``` i tried about everything i could find, but I start thinking I'm the only one. help? maybe? – flypenguin Dec 10 '20 at 21:49
  • 1
    @flypenguin It looks like you're actually not using the `arch` command, which is why Homebrew is refusing to install. Prepend what you pasted above with `arch --x86_64`. – Jacob Ford Jan 04 '21 at 01:53
  • This is a neat solution, but I have problems using oh-my-zsh plugins: they use `brew --prefix` to check if the corresponding package is installed, and at that point the `PATH` doesn't contain the 'native Homebrew' bin, so it uses `/usr/local/bin` which is the Rosetta based. Any suggestion how to resolve this? – Katona Aug 25 '21 at 09:24
  • 1
    vscode has apple silicon and intel builds. If you use the intel build, the integrated terminal with be i386. – Devin Rhode Feb 15 '22 at 18:44
  • Love ya brow, but why it's "if you are still on bash"? – Ron Wang Mar 29 '22 at 23:17
  • 1
    @RonWang The macOS default terminal is now `zsh`. – Jacob Ford Mar 31 '22 at 11:25
  • Didn't work for me. When I would switch to intel it would say "command arch not found" or something. – Sam Jun 07 '23 at 03:29
  • Amazing answer, wow – Devender Goyal Jul 10 '23 at 06:53
24
  1. Install Native Homebrew

    ❯ arch --arm64 zsh -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    

    all Homebrew related stuffs are in /opt/homebrew.

  2. Install Rosetta Homebrew

    ❯ arch --x86_64 zsh -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
    

    all Homebrew related stuffs are in /usr/local.

  3. Configuring ~/.zshrc to use Brew defaultly based on arch,

    # Multiple Homebrews on Apple Silicon
    if [ "$(arch)" = "arm64" ]; then
        eval "$(/opt/homebrew/bin/brew shellenv)"
        export PATH="/opt/homebrew/opt/python@3.8/bin:$PATH"
        # export LDFLAGS="-L/opt/homebrew/opt/python@3.8/lib" # For compilers to find python@3.8
    else
        eval "$(/usr/local/bin/brew shellenv)"
        export PATH="/usr/local/opt/python@3.7/bin:$PATH"
        export PATH="/usr/local/opt/python@3.9/bin:$PATH"
        # export LDFLAGS="-L/usr/local/opt/python@3.7/lib" # For compilers to find python@3.7
    fi
    
  4. Test

    ❯ arch
    arm64
    ❯ which brew
    /opt/homebrew/bin/brew
    ❯ arch -x86_64 zsh
    ❯ arch
    i386
    ❯ which brew
    /usr/local/bin/brew
    # set alias as you like
    ❯ rzsh='arch -x86_64 zsh'
    
huyz
  • 2,297
  • 3
  • 25
  • 34
liviaerxin
  • 579
  • 6
  • 13
  • Ooh, nice. Note that this uses the appropriate `brew` based on your _current_ arch (great for cross-architecture scripting), but doesn’t give you two different commands to type from _within_ ARM to choose which `brew` you want to use. – Jacob Ford Jul 19 '21 at 15:40
  • Awesome, thank you! How does the installer know to put the arm installation in /opt/homebrew/ and the intel installation in /usr/local/? – jtlz2 Mar 15 '22 at 08:50
  • Error: `bash is required to interpret this script` – jtlz2 Mar 15 '22 at 08:57
  • Also: Why 3.8 on arm and 3.7, 3.9 on intel? – jtlz2 Mar 15 '22 at 08:59
  • But anyway, this doesn't work for me - both installations point to the same place! – jtlz2 Mar 15 '22 at 09:01
  • Yeah, the homebrew installer knows the current arch environment then put itself in `/opt/homebrew/` for `arm` and `/usr/local/` for `x86`. – liviaerxin Mar 18 '22 at 04:48
  • In addition, I install py 3.8 in `arm` and install py 3.7, 3.9 in `x86` all by `brew`. Then you can find that the py 3.8 is universal/arm built and py 3.7, 3.9 are x86 built. So you need to set up respective `PATH` for matching py in the different arch. – liviaerxin Mar 18 '22 at 05:02
  • Please check [https://docs.brew.sh/Installation](https://docs.brew.sh/Installation) to find the detailed FAQ. – liviaerxin Mar 18 '22 at 05:08