Yosemite上的Rails / Nokogiri安装错误

时间:2015-03-30 21:42:59

标签: ruby-on-rails ruby nokogiri homebrew osx-yosemite

将我的Macbook空气升级到优胜美地后,我无法安装导轨。有一连串的错误,其中一些我已经能够解决。目前的错误,我几天来一直没有成功解决,看起来像这样

naomi$ sudo gem install rails
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
ERROR: Failed to build gem native extension.

/Users/naomi/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150330-94892-1kd8mkt.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
--without-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=/Users/naomi/.rvm/rubies/ruby-2.2.1/bin/$(RUBY_BASE_NAME)
--help
--clean
--use-system-libraries
/Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- openssl (LoadError)
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/https.rb:22:in `<top (required)>'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:3:in `<top (required)>'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from extconf.rb:395:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0/nokogiri-1.6.6.2/gem_make.out

当我尝试安装nokogiri时,我得到了

naomi$ gem install nokogiri
Building native extensions.  This could take a while...
ERROR:  Error installing nokogiri:
ERROR: Failed to build gem native extension.

/Users/naomi/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150330-94919-1a0u8fd.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
--without-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=/Users/naomi/.rvm/rubies/ruby-2.2.1/bin/$(RUBY_BASE_NAME)
--help
--clean
--use-system-libraries
/Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- openssl (LoadError)
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/net/https.rb:22:in `<top (required)>'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/gems/2.2.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:3:in `<top (required)>'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
from /Users/naomi/.rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
from extconf.rb:395:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/naomi/.rvm/gems/ruby-2.2.1/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /Users/naomi/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-14/2.2.0/nokogiri-1.6.6.2/gem_make.out

我正在运行OSX 10.10.2,ruby -v给了我

ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin14]

注意:这可能看似重复,但我认为不是:我一直在研究在SO和其他地方建议的解决方案数天,并且已发布的解决方案尚未解决错误。使用开发人员工具安装了Xcode,因此xcode-select --install给了我

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

非常感谢您的帮助!

2 个答案:

答案 0 :(得分:2)

我在Nokogiri's site找到了相关问题(最后一篇文章)。他们用以下方法解决了问题:

sudo gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.‌​platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --use-system-libraries

答案 1 :(得分:1)

问题

出于某种原因,Apple的Yosemite OSX版本没有 libxml2 的系统可访问安装。 Nokogiri需要这个才能编译,幸运的是Xcode有一个与之捆绑的libxml2版本 - 我们只需要在安装gem时指定它。让Nokogiri正确安装非常重要,因为到目前为止,Rails 4.2.1.rc4会自动尝试安装它,你会感到痛苦。

修复

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2