ruby - 无法安装 gem - extconf.rb 失败

标签 ruby macos-mojave

我将 macos 升级到 Mojave 并重新安装了 xcode、xcode CLT、ruby 等。然后当我尝试时:

gem install nokogiri

我收到以下错误(安装其他 gem 时出现类似错误):

ERROR: Failed to build gem native extension.

current directory: /usr/local/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.5/ext/nokogiri
/usr/local/opt/ruby/bin/ruby -r ./siteconf20181209-20884-etfc5r.rb extconf.rb
checking if the C compiler accepts ... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

我检查了 mkmf.log,其中包含以下内容:

"clang -o conftest -I/usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0/x86_64-darwin18 -I/usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0/ruby/backward -I/usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0 -I.  -I/usr/local/opt/libyaml/include -I/usr/local/opt/openssl/include -I/usr/local/opt/readline/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens  -fno-common -pipe conftest.c  -L. -L/usr/local/Cellar/ruby/2.5.3_1/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib     -lruby.2.5.3  -lpthread -ldl -lobjc "
In file included from conftest.c:1:
In file included from /usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0/ruby.h:33:
In file included from /usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0/ruby/ruby.h:29:

文字就这样持续了一会儿。我也cd到nokogiri文件夹,直接运行extconf.rb,出现如下错误:

checking if the C compiler accepts ... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.`

Provided configuration options:
--with-opt-dir
--with-opt-include

...(为简洁起见跳过类似内容,继续往下看)

usr/local/Cellar/ruby/2.5.3_1/lib/ruby/2.5.0/mkmf.rb:456:in 'try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.

我尝试安装 xcode。我还安装了标题并确认了许可证。起初我以为它与 GCC 有关,但 mkmf 文件显示问题出在 Clang

希望有人能帮忙。

最佳答案

我必须运行以下神秘命令才能安装 nokogiri。基本上这需要让我的 C 编译器在 mac osx Mojave 中工作,在之前的操作系统中一切正常(我认为是优胜美地...)

这是升级 osx 时一个(有点)显而易见的步骤:

xcode-select --install

我也必须这样做,如果没有谷歌和 this post,我永远不知道该怎么做

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

最后,我不得不同意 xcode 许可证(发现我必须在安装 nokogiri 失败时通过 makefile 日志来执行此操作...)

sudo xcodebuild -licence

它会提示你最终输入“同意”

最后,对于包含 nokogiri 的新 Rails 项目,继续使用 bundle 可以正常工作。成功!

关于ruby - 无法安装 gem - extconf.rb 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53700851/

相关文章:

macos - 在 Mojave 上安装 Brew

ruby - 轮胎 gem 分析输入文本

ruby - 如何在 ruby​​ 中执行惯用的非递归展平?

Ruby:使用一个请求删除带有前缀的所有 S3 对象

ruby-on-rails - f.check_box checked => true for ruby​​ on rails

node.js - -bash ng 命令未找到 Mojave

javascript - 在 Rails 3 中使用 AJAX 删除记录

python - tkinter 的按钮文本在 mojave 中不起作用

python - 在 mac os 和 python 中设置 SIGKILL 处理程序时出现 OSError

Xcode 10.1 未从 10.0 更新