【问题标题】:Install Ruby development tools for gem installation on OSX Catalina在 OSX Catalina 上安装用于 gem 安装的 Ruby 开发工具
【发布时间】:2021-01-12 03:37:17
【问题描述】:

我知道这个问题有很多例子。我已经完成了这些答案中的所有操作,但 4 小时后却一无所获。

我正在尝试在 Catalina 10.15.7 上安装 gem 并获得越来越流行的

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.

有了这个额外的上下文

ERROR:  Error installing ffi:
    ERROR: Failed to build gem native extension.

    current directory: /Users/bmanica/.chefdk/gem/ruby/2.4.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200925-10024-qilctf.rb extconf.rb --with-cflags\=-save-temps\=obj\ -o\ tmp/a.o

通过调用安装时

gem install ffi  -- --with-cflags="-save-temps=obj -o tmp/a.o"

绕过 Catalina 严格的权限规则。

我刚刚下载了 XCode 和命令行工具:

> xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
> xcode-select -p
/Applications/Xcode.app/Contents/Developer
> ls /Applications/Xcode.app/Contents/Developer
Applications    Library     Makefiles   Platforms   Toolchains  Tools       usr

我通过以下方式至少接受了四次许可

sudo xcodebuild -license accept

我试过了

sudo xcode-select -switch /

正如Gem installation error: You have to install development tools first 建议的那样。我不在 Windows 上,所以 ruby​​installer 链接对我没有帮助。

Can't Find ffi.h When Installing ffi ruby gem 引用了我正在尝试安装的确切 gem,但如所示 xcode-select --install 不是答案。

Developer tools issues when installing Ruby gems 中的答案也无济于事;我已经有了brew install opensslbrew install libffi 并导出了它告诉我的变量:

> set | grep FLAGS
CPPFLAGS=-I/usr/local/opt/libffi/include
LDFLAGS=-L/usr/local/opt/libffi/lib
> set | grep PATH
PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig

我也尝试过How to update Xcode from command line 中的建议 - xcode-select -r 什么都不做,xcode-select -s /Library/Developer/CommandLineTools 什么都不做,$ sudo rm -rf /Library/Developer/CommandLineTools 阻止 xcode-select --install 工作,另外我还是移动了它并重新下载了命令行 dmg来自 Apple 开发者网站的软件包。还是同样的问题。

接下来我应该怎么做才能安装这个 gem?

【问题讨论】:

  • 接受 XCode 许可证:sudo xcodebuild -license accept。另外,使用 Ruby 管理器; 不要在你的系统 Ruby 中安装 gems。
  • 抱歉,我已经接受了至少四次许可。
  • 一点建议。不要以“是的,我已经阅读了类似这样的其他问题”作为开头,而只是介绍您到目前为止所研究的内容。写得这么好的问题不需要它,它真的只是把它拖下来。
  • 我遇到了同样的问题。我这样解决了stackoverflow.com/questions/66081684/…

标签: ruby rubygems macos-catalina


【解决方案1】:

几个小时后终于拿到了。 我按照this的指令,稍微改了一下

  1. 确保已安装 brew。如果不 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

  2. 将外壳设置为zsh curl -L http://install.ohmyz.sh | sh

或者,设置路径

  1. eval "$(rbenv init -)"

  2. 安装 Ruby 版本管理器 brew update brew install rbenv ruby-build

  3. 安装 Ruby rbenv install 2.6 # 我使用我的系统默认版本号,因为我不确定它是否与我的 OS X 系统版本混淆。 rbenv global 2.6 rbenv rehash

  4. 将其添加到您的 zsh echo 'eval "$(rbenv init -)"' >> ~/.zshrc source ~/.zshrc

这对我有用。所有其他的东西,比如安装 Xcode,接受 Xcode 许可证,Xcode 命令行工具都没有。

【讨论】:

  • 非常感谢,这对我有用
【解决方案2】:

从错误消息中的路径名判断,您正在尝试修改 Apple 的 System Ruby。 这是不允许的

Apple 的 System Ruby专供供 macOS 内部使用和/或支持旧版应用程序。你不得使用它,你肯定不得修改它。修改它会否定整个“对遗留应用程序的支持”。

Apple 自己在the release notes for macOS 10.15 Catalina 中有以下说法:

脚本语言运行时

弃用

  • macOS 中包含 Python、Ruby 和 Perl 等脚本语言运行时,以便与旧版软件兼容。默认情况下,macOS 的未来版本将不包含脚本语言运行时,并且可能需要您安装其他软件包。如果您的软件依赖于脚本语言,建议您将运行时捆绑在应用程序中。 (49764202)

在 macOS 上安装 Ruby 有很多很多选项,包括但不限于自己编译、下载预编译的二进制文件、Homebrewruby-installruby-buildRVM。在 macOS 上管理 Ruby 安装有很多选项,包括但不限于chrubyasdfrbenv 和 RVM。

其中大多数具有额外的优势,即它们支持比 Apple 发布的版本更新的版本,更有趣的是,它们支持不同的实现,而不仅仅是 YARV。我个人最喜欢的是TruffleRuby,它在GraalVM 上运行时,对我来说快了1000 倍,具体取决于基准测试。

请不要使用 System Ruby。

【讨论】:

  • 我在发布问题后试图让 rbenv 再工作两个小时,但也没有用。我已经放弃了,请注意。
猜你喜欢
  • 2021-01-03
  • 2021-12-17
  • 1970-01-01
  • 2020-02-14
  • 2020-08-12
  • 1970-01-01
相关资源
最近更新 更多