【问题标题】:How can I install Homebrew into /opt/?如何将 Homebrew 安装到 /opt/?
【发布时间】:2024-01-02 05:36:01
【问题描述】:

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

无法以 Intel 默认前缀 (/usr/local) 安装在 ARM 处理器上的 Homebrew 中! 请使用以下之一在 /opt/homebrew 中创建新安装 “替代安装”来自: https://docs.brew.sh/Installation 您可以迁移以前安装的公式列表: 酿造捆绑转储

我尝试通过 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.  

错误:无法以英特尔默认前缀 (/usr/local) 安装在 ARM 处理器上的 Homebrew 中! 请使用以下之一在 /opt/homebrew 中创建新安装 “替代安装”来自: https://docs.brew.sh/Installation 您可以迁移以前安装的公式列表: 酿造捆绑转储

编辑 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)

【问题讨论】:

  • 你不能 mkdir /opt/homebrew ?即使使用 sudo?
  • 我用 sudo 再次尝试,它开始工作然后停止“tar:错误退出因以前的错误而延迟。”

标签: macos homebrew apple-silicon


【解决方案1】:

我用过诺亚鲁宾写的脚本;

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

工作就像一个魅力!这是他关于此主题的 youtube 视频以获取更多信息; https://youtu.be/nv2ylxro7rM

编辑:忘了提,这个脚本将自制软件安装到 /opt/homebrew 中

【讨论】:

  • 此处的链接视频演示了如何/何时使用 Rosetta 2 运行以及何时运行本机。我没有发现任何其他细节涉及到这个细节,这似乎很重要。
  • 无法在 /usr/local/var/homebrew/locks 中创建更新锁!通过运行修复权限: sudo chown -R $(whoami) /usr/local/var/homebrew 警告:您的 HOMEBREW_PREFIX 设置为 /usr/local 但 HOMEBREW_CELLAR 设置为 /opt/homebrew/Cellar。您当前的 HOMEBREW_CELLAR 位置将停止访问所有瓶子。”错误:无法在 Homebrew ARM 处理器 Intel 默认前缀 (/usr/local) 中安装!请使用来自 @987654322 的“替代安装”之一在 /opt/homebrew 中创建新安装@ 可以迁移你之前安装的公式:brew bundle dump
  • 如果我运行 brew bundle 转储,会有什么影响
【解决方案2】:

我解决了它在 Rosetta Terminal 下运行

  1. 在 Utilities 文件夹中找到终端应用程序(Finder> Go menu > Utilities)

  2. 选择 Terminal.app 并右键单击它,然后选择“复制”重命名复制的终端应用程序 明显而独特,例如“罗塞塔码头”

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

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

【讨论】:

  • You are using macOS 11.0. We do not provide support for this released but not yet supported version. You will encounter build failures with some formulae. Please create pull requests instead of asking for help on Homebrew's GitHub, Twitter or any other official channels. You are responsible for resolving any issues you experience while you are running this released but not yet supported version. Error: gtk+3 dependencies not built for the x86_64 CPU architecture: python@3.9 was built for arm64 –
  • 这个解决方法对我有用,也无法按照their own documentation 的建议在opt/homebew 中实际安装自制软件
【解决方案3】:

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

【讨论】: