如何将 Homebrew 安装到 /opt/?

How can I install Homebrew into /opt/?

我正在使用新款 M1 MacBook Pro。我正在尝试通过 Homebrew 安装 gtk+3(它有原生的 apple silicon 支持)。首先它告诉我

Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)! Please create a new installation in /opt/homebrew using one of the "Alternative Installs" from: https://docs.brew.sh/Installation You can migrate your previously installed formula list with: brew bundle dump

我尝试通过 Rosetta 2 运行 终端,但是 gtk+3 需要 ARM 支持才能安装,所以没用。

我试图在/opt/中手动解压缩docs.brew.sh中的代码行,但它告诉我我没有权限。我试图 sudo 它,但无济于事。有帮助吗?

编辑 1:完整消息:

brew install gtk+3  
Updating Homebrew...
==> Auto-updated Homebrew!  
Updated 1 tap (homebrew/core).  
==> New Formulae  
libbsd  
==> Updated Formulae  
Updated 18 formulae.  

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)! Please create a new installation in /opt/homebrew using one of the "Alternative Installs" from: https://docs.brew.sh/Installation You can migrate your previously installed formula list with: brew bundle dump

编辑 2:在 /opt/ 中创建了一个名为 'Home-brew' 的文件夹并在那里打开了终端,尝试了 sudo 和所有操作:

oresttokovenko@Orests-MacBook-Pro-2 Homebrew % sudo chmod 755          
Password:
usage:  chmod [-fhv] [-R [-H | -L | -P]] [-a | +a | =a  [i][# [ n]]] mode|entry file ...
    chmod [-fhv] [-R [-H | -L | -P]] [-E | -C | -N | -i | -I] file ...
oresttokovenko@Orests-MacBook-Pro-2 Homebrew % https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
zsh: no such file or directory: https://github.com/Homebrew/brew/tarball/master
tar: could not chdir to 'homebrew'

oresttokovenko@Orests-MacBook-Pro-2 Homebrew % curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   128  100   128    0     0    254      0 --:--:-- --:--:-- --:--:--   255
  0 1979k    0   598    0     0    682      0  0:49:32 --:--:--  0:49:32   682tar: could not chdir to 'homebrew'

  1 1979k    1 33478    0     0  34728      0  0:00:58 --:--:--  0:00:58  364k
curl: (23) Failed writing body (0 != 1370)
oresttokovenko@Orests-MacBook-Pro-2 Homebrew % sudo curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   128  100   128    0     0    348      0 --:--:-- --:--:-- --:--:--   348
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0tar: could not chdir to 'homebrew'

  1 1979k    1 34138    0     0  41887      0  0:00:48 --:--:--  0:00:48  129k
curl: (23) Failed writing body (0 != 1370)

我在Rosetta Terminal

下解决了运行
  1. 在实用程序文件夹中找到终端应用程序(Finder> 转到菜单 > 实用程序)

  2. Select Terminal.app 并右键单击它,然后选择“复制”将复制的终端应用程序重命名为某物 明显而独特,例如“Rosetta Terminal”

  3. 现在select新鲜 重命名为“Rosetta Terminal”应用程序并右键单击并选择“获取信息” (或按 Command+i)

  4. 选中“使用 Rosetta 打开”复选框,然后 像往常一样关闭 Get Info window 运行 “Rosetta Terminal”, 将完全支持 Homebrew 和其他 x86 命令行应用程序

对于现在遇到此问题的任何人,我多次收到 curl: (23) Failed writing body (0 != 1370) 错误,直到我意识到我正在 运行 从我的主目录中执行 curl/tar 命令。如果我 cd 进入 /opt 然后 运行 命令,它会按预期工作。

我用过Noah Rubin写的脚本;

/bin/bash -c "$(curl -fsSL https://gist.githubusercontent.com/nrubin29/bea5aa83e8dfa91370fe83b62dad6dfa/raw/48f48f7fef21abb308e129a80b3214c2538fc611/homebrew_m1.sh)"

工作得非常棒!这是他关于此主题的 youtube 视频以获取更多信息; https://youtu.be/nv2ylxro7rM

编辑:忘记提及,此脚本将自制程序安装到 /opt/homebrew