ruby-on-rails - 安装 rails 时出错,无法构建 gem native 扩展

标签 ruby-on-rails ruby

我正在关注 this Go Rails tutorial当我到达安装 rails 的步骤时遇到了麻烦。我在打电话

sudo gem install rails -v 5.0.1

在终端中出现此错误:

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

    current directory: /usr/local/lib/ruby/gems/2.4.0/gems/nokogiri-1.7.0.1/ext/nokogiri
/usr/local/opt/ruby/bin/ruby -r ./siteconf20170302-50105-1af2foa.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
Using mini_portile version 2.1.0
checking for iconv.h... yes
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** 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
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/local/Cellar/ruby/2.4.0/bin/$(RUBY_BASE_NAME)
    --help
    --clean
    --use-system-libraries
    --enable-static
    --disable-static
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --enable-cross-build
    --disable-cross-build

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /usr/local/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0/nokogiri-1.7.0.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/lib/ruby/gems/2.4.0/gems/nokogiri-1.7.0.1 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0/nokogiri-1.7.0.1/gem_make.out

我真的不知道该怎么做。我试过重新安装卸载和重新安装 zlib 但它似乎没有改变任何东西。顺便说一下,我使用的是 OS X Sierra 10.12.3 版。

最佳答案

this thread 解决使用

sudo gem install rails -- --use-system-libraries --with-xml=/usr/local/Cellar/libxml2/

关于ruby-on-rails - 安装 rails 时出错,无法构建 gem native 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42563681/

相关文章:

ruby-on-rails - 验证与模型的错误消息关联

ruby-on-rails - 为什么这段 Ruby 代码无法写入日志文件?

ruby-on-rails - Ruby API 请求中的 Yahoo Oauth - 签名无效

ruby-on-rails - Heroku rake 数据库 :migrate

ruby-on-rails - Mongoid:如何查询值为 nil 的所有对象?

ruby-on-rails - 了解 Rails 验证 : what does allow_blank do?

ruby-on-rails - Rails 4,将 "\n"替换为 "
",用于 excel 中的 XML 电子表格

ruby-on-rails - 在 Ruby on Rails 上的 ActiveRecord 中获取下一条/上一条记录

java - 桌面应用程序的自动化击键

mysql - Rails ActiveRecord 加入并包含在同一个查询中?