18

我想在 Apple Silicon Mac 上同时安装和运行两个版本的 Homebrew:一个 ARM64 版本和一个在 Rosetta 2 下运行的 Intel 版本。

知道我可以预先添加任何 brew 命令arch --x86_64来模拟 Intel 执行该命令,但这可能会导致您已经为 ARM64 构建的依赖项的公式发生冲突。例如:

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

如何安装和运行两个独立的 Homebrew 版本(一个用于本机 ARM64,一个用于模拟 Intel),保持每个已安装的公式和依赖项分开?

4

2 回答 2

50
  1. 在 Apple Silicon 上本地安装 Homebrew /opt/homebrew

    mkdir homebrew && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
    
  2. 将 Intel-emulated Homebrew 安装到默认值/usr/local

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

    如果您尚未安装 Rosetta 2,则需要先运行softwareupdate --install-rosetta

  3. 为英特尔自制软件创建别名。我打电话给我是brow因为 O 代表老。但是,嘿,你做你自己的事。

    ~/.zshrc(或您的 shell 的等效项)中添加:

    alias brow='arch --x86_64 /usr/local/Homebrew/bin/brew'
    
  4. 将 ARM Homebrew 添加到您的 PATH。

    ~/.zshrc(或您的 shell 的等效项)中添加:

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

    如果你还在,bash那就是PATH=/opt/homebrew/bin:$PATH

  5. 确认

    which brew应该返回/opt/homebrew/bin/brew

    brew --prefix应该返回/opt/homebrew

    which brow应该返回brow: aliased to arch --x86_64 /usr/local/Homebrew/bin/brew

    brow --prefix应该返回/usr/local


如果您在两个 Homebrews 中安装了相同的命令,它将默认为 Apple Silicon ( /opt/homebrew/),因为我们在 PATH 中添加了该命令。要覆盖,请使用完整路径 ( /usr/local/bin/youtube-dl) 运行命令,或覆盖您PATH的一个命令 ( PATH=/usr/local/bin youtube-dl)。

我还在.zshrc( alias ib='PATH=/usr/local/bin') 中创建了另一个方便的别名,因此我可以在任何 Homebrew 安装的命令前面加上ib强制使用该命令的 Intel 版本:

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

如果您希望 Intel 作为默认值brew,请添加/opt/homebrew/bin到 PATH 的末尾而不是开头。

于 2020-11-22T05:43:03.480 回答
9
  1. 安装本机自制软件

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

    所有与 Homebrew 相关的东西都在/opt/homebrew.

  2. 安装 Rosetta Homebrew

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

    所有与 Homebrew 相关的东西都在/usr/local.

  3. 配置~/.zshrc为默认使用Brew基于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. 测试

    ❯ 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'
    
于 2021-07-19T15:37:31.730 回答