错误为宝石安装nokogiri和捆绑安装FOR Middleman应用程序

时间:2015-08-28 20:16:29

标签: ruby-on-rails ruby gem rubygems middleman

我从零开始创建一个Middleman应用程序。每当我尝试运行服务器时,即middleman server我收到一个错误(下面),告诉我“安装nokogiri(1.6.6.2)时出错,而Bundler无法继续。”

但是,当我尝试安装nokogiri(1.6.6.2)时,我收到另一个错误(下面),说“错误:安装nokogiri时出错:错误:无法构建gem原生扩展。”

然后我尝试bundle install我的gemfile但收到另一个错误。谁能告诉我我可能会忽略什么?

每当我尝试运行middleman server命令时,我都会这样:

/Library/Ruby/Site/2.0.0/rubygems/dependency.rb:315:in `to_specs': Could not find 'nokogiri' (>= 1.3.3) among 67 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/Wilhelm/.gem/ruby/2.0.0:/Library/Ruby/Gems/2.0.0:/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0', execute `gem env` for more information
    from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1311:in `block in activate_dependencies'
    from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1300:in `each'
    from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1300:in `activate_dependencies'
    from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1282:in `activate'
    from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1314:in `block in activate_dependencies'
    from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1300:in `each'
    from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1300:in `activate_dependencies'
    from /Library/Ruby/Site/2.0.0/rubygems/specification.rb:1282:in `activate'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_gem.rb:67:in `block in gem'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_gem.rb:66:in `synchronize'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_gem.rb:66:in `gem'
    from /usr/bin/middleman:22:in `<main>'

以下是我的Gemfile的内容:

# If you do not have OpenSSL installed, update
# the following line to use "http://" instead
source 'https://rubygems.org'

gem "middleman", "~>3.4.0"

# Live-reloading plugin
gem "middleman-livereload", "~> 3.1.0"

# For faster file watcher updates on Windows:
gem "wdm", "~> 0.1.0", :platforms => [:mswin, :mingw]

# Windows does not come with time zone data
gem "tzinfo-data", platforms: [:mswin, :mingw, :jruby]

以下是我bundle install的结果:

Fetching gem metadata from https://rubygems.org/.............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies...
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.0
Using thread_safe 0.3.5
Using tzinfo 1.2.2
Using activesupport 4.2.4
Using bundler 1.8.2
Using mime-types 2.6.1
Using mini_portile 0.6.2

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20150828-20513-wkpoce.rb extconf.rb --use-system-libraries
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 system libraries.
libxml2 version 2.6.21 or later is required!
*** 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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    --help
    --clean
    --use-system-libraries
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-pkg-config
    --without-pkg-config
    --with-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-exslt-dir
    --without-exslt-dir
    --with-exslt-include
    --without-exslt-include=${exslt-dir}/include
    --with-exslt-lib
    --without-exslt-lib=${exslt-dir}/lib
    --with-libexslt-config
    --without-libexslt-config

extconf failed, exit code 1

Gem files will remain installed in /var/folders/zn/zh_8qnr573x4wgbjz6gqz72w0000gn/T/bundler20150828-20513-11hlulx/nokogiri-1.6.6.2/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /var/folders/zn/zh_8qnr573x4wgbjz6gqz72w0000gn/T/bundler20150828-20513-11hlulx/nokogiri-1.6.6.2/extensions/universal-darwin-14/2.0.0/nokogiri-1.6.6.2/gem_make.out
An error occurred while installing nokogiri (1.6.6.2), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.6.6.2'` succeeds before bundling.

以下是我sudo gem install nokogiri -v '1.6.6.2'的结果:

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

        /Users/Wilhelm/.rbenv/versions/1.9.3-dev/bin/ruby 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.
-----
The file "/usr/include/iconv.h" is missing in your build environment,
which means you haven't installed Xcode Command Line Tools properly.

To install Command Line Tools, try running `xcode-select --install` on
terminal and follow the instructions.  If it fails, open Xcode.app,
select from the menu "Xcode" - "Open Developer Tool" - "More Developer
Tools" to open the developer site, download the installer for your OS
version and run it.
-----
*** 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/Wilhelm/.rbenv/versions/1.9.3-dev/bin/ruby
    --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


Gem files will remain installed in /Users/Wilhelm/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /Users/Wilhelm/.rbenv/versions/1.9.3-dev/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.6.2/ext/nokogiri/gem_make.out

2 个答案:

答案 0 :(得分:1)

我在几个系统配置中遇到过这种情况。它总是最终成为开发库依赖项。如果是我,一次一个,我会安装这些并尝试捆绑安装:

libxslt-dev
libxml2-dev
ruby-dev

取决于你的系统(我认为它们是-devel而不是-dev)。

答案 1 :(得分:1)

此命令:

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

this github issue找到的

解决了我的问题。老实说,我不完全确定为什么如果有人可以附加评论,阐明究竟发生了什么,将非常感激。