Mac M1 上的 Ruby 问题

问题描述 投票:0回答:2

我在我的 M1 Mac 上安装 Ruby 和使用自制软件时遇到问题

我正在尝试安装 Ruby,这样我就可以通过 Jekyll 启动一个网站。我正在按照 Jekyll 网站上的安装指南 运行命令

ruby-install ruby 3.1.3
,但我仍然收到相同的错误消息。

这里是完整的输出供参考:

kamilszafraniak@Kamils-Air ~ % ruby-install ruby 3.1.3
>>> Installing ruby 3.1.3 into /Users/kamilszafraniak/.rubies/ruby-3.1.3 ...
>>> Installing dependencies for ruby 3.1.3 ...
Warning: [email protected] 1.1.1t is already installed and up-to-date.
To reinstall 1.1.1t, run:
  brew reinstall [email protected]
Warning: readline 8.2.1 is already installed and up-to-date.
To reinstall 8.2.1, run:
  brew reinstall readline
Warning: libyaml 0.2.5 is already installed and up-to-date.
To reinstall 0.2.5, run:
  brew reinstall libyaml
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
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
!!! Installing dependencies failed!

我从 StackOverflow 尝试了许多不同的解决方案,但我不断收到错误消息:

Error: Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
我尝试在不同的前缀上安装 Homebrew,更改默认路径,并使用
arch -x86_64 brew install
命令前缀,但都没有这些解决方案奏效了。

我不知道下一步该怎么做,因为我尝试了很多不同的解决方案。如果有人对此问题有经验,我将不胜感激。如果您需要我计算机上的任何其他信息或文件,请告诉我。

(这只是我正在努力解决的一个具体问题,我需要有人帮我一劳永逸地解决我设备上的自制软件问题。)

谢谢!

编辑 1:运行

brew doctor
命令,收到以下警告:

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  node
  [email protected]

Warning: Your Homebrew's prefix is not /opt/homebrew.

Many of Homebrew's bottles (binary packages) can only be used with the default prefix.
Consider uninstalling Homebrew and reinstalling into the default prefix.
It is expected behaviour that some formulae will fail to build in this unsupported configuration.
It is expected behaviour that Homebrew will be buggy and slow.
Do not create any issues about this on Homebrew's GitHub repositories.
Do not create any issues even if you think this message is unrelated.
Any opened issues will be immediately closed without response.
Do not ask for help from Homebrew or its maintainers on social media.
You may ask for help in Homebrew's discussions but are unlikely to receive a response.
Try to figure out the problem yourself and submit a fix as a pull request.
We will review it but may or may not accept it.

我向 GPT 3.5 发送了第一个警告,它告诉我:

要链接 Homebrew Cellar 中未链接的小桶,请运行 brew link node 和 brew link [email protected]。这将确保依赖于这些小桶的任何公式都可以正确访问它们。

我这样做了并且:

kamilszafraniak@Kamils-Air ~ % brew link node
Linking /usr/local/Cellar/node/20.1.0... 
Error: Could not symlink bin/node
Target /usr/local/bin/node
already exists. You may want to remove it:
  rm '/usr/local/bin/node'

To force the link and overwrite all conflicting files:
  brew link --overwrite node

To list all files that would be deleted:
  brew link --overwrite --dry-run node
kamilszafraniak@Kamils-Air ~ % brew link --overwrite node
Linking /usr/local/Cellar/node/20.1.0... 
Error: Could not symlink include/node/common.gypi
/usr/local/include/node is not writable.
kamilszafraniak@Kamils-Air ~ % rm '/usr/local/bin/node'
rm: /usr/local/bin/node: No such file or directory
kamilszafraniak@Kamils-Air ~ % rm '/usr/local/bin/node 
quote> 
kamilszafraniak@Kamils-Air ~ % rm '/usr/local/bin/node'
rm: /usr/local/bin/node: No such file or directory

然后我尝试了

sudo brew link --overwrite node

Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

我刚刚重新安装了 homebrew — 并使用 AI 帮助我完成所有事情,现在 brew doctor 没有显示任何警告,我将再次安装 ruby 并确认没有问题。

现在,我再次运行相同的命令并收到相同的错误,现在运行

brew doctor
后,我得到了前面所述的相同错误。我回到第一广场。我想 ruby 必须安装一个特定的前缀?那是什么前缀

很抱歉冗长的信息。

ruby homebrew jekyll apple-m1
2个回答
0
投票

rbenv 帮助我在 M1 Mac 上安装 Ruby:

  1. brew 安装 rbenv ruby-build
  2. rbenv 初始化
  3. 关闭您的终端窗口并打开一个新窗口以使您的更改生效。
  4. rbenv 安装 3.1.3

https://github.com/rbenv/rbenv


0
投票

您似乎遇到了在 ARM 处理器上使用 Homebrew 安装 Ruby 的问题。错误消息建议您在 /opt/homebrew 目录中创建一个新的 Homebrew 安装。

以下是成功安装 Ruby 的步骤:

  1. 卸载 Homebrew(如果已经安装):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"

  1. 在/opt/homebrew目录下安装Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. 更新您的 shell 配置文件(例如,~/.bash_profile、~/.zshrc)以正确设置 Homebrew 路径:
eval "$(/opt/homebrew/bin/brew shellenv)"

  1. 关闭并重新打开终端以加载更新的配置。
  2. 使用 Homebrew 安装 Ruby:
brew install [email protected]

  1. 验证安装:
ruby -v

它应该显示安装的 Ruby 版本,确认安装成功。

© www.soinside.com 2019 - 2024. All rights reserved.