新手问题 安装 Rails 失败,多次尝试未果

mamian · 2016年11月30日 · 最后由 mamian 回复于 2016年11月30日 · 2926 次阅读

当我输入

sudo gem install rails

Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

    /usr/local/opt/ruby/bin/ruby -r ./siteconf20161130-77662-u8g67w.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.
*** 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.3.1_2/bin/$(RUBY_BASE_NAME)
    --help
    --clean
    --use-system-libraries
/usr/local/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:308:in `to_specs': Could not find 'mini_portile2' (~> 2.1.0) among 6 total gem(s) (Gem::MissingSpecError)
Checked in 'GEM_PATH=/Users/MAMIAN/.gem/ruby/2.3.0:/usr/local/lib/ruby/gems/2.3.0:/usr/local/Cellar/ruby/2.3.1_2/lib/ruby/gems/2.3.0', execute `gem env` for more information
    from /usr/local/lib/ruby/site_ruby/2.3.0/rubygems/dependency.rb:320:in `to_spec'
    from /usr/local/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
    from extconf.rb:468:in `<main>'

extconf failed, exit code 1

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

ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin15]
rvm 1.27.0 (latest) by Wayne E. Seguin [email protected], Michal Papis [email protected] [https://rvm.io/]

Google 查了查,上面的方法都试了,还是不行,特地来问下

macOS 10.12

已经解决了,利用 rvm 安装了 ruby 解决

apt-get install ruby-dev

#1 楼 @yunshang 抱歉,我的电脑是 macOS

#2 楼 @mamian 不能这样吗 brew install ruby-dev😆

参照 Wiki,估计是要 Xcode。

报错信息明显是版本的问题,贴出你的 ruby 和 rvm 的版本

看错误信息是两个问题:

  1. Nokogiri 安装失败,原因是缺少库(libxml2, libxslt),请用 RVM 安装 Ruby 就会带这些东西,或者参考 Nokogiri Building native extensions
  2. Could not find 'mini_portile2' (~> 2.1.0)

#5 楼 @easonlovewan

ruby 2.2.3p173 
rvm 1.27.0 (latest)
mamian 关闭了讨论。 11月30日 10:43
mamian 重新开启了讨论。 11月30日 10:43

已经解决了,利用 rvm 安装了 ruby 解决

mamian 关闭了讨论。 11月30日 10:43
需要 登录 后方可回复, 如果你还没有账号请 注册新账号