捆绑安装时,Nokogiri发生错误(OSx Mavericks)

时间:2014-08-13 11:08:59

标签: ruby-on-rails ruby gem nokogiri

我是rails的新手,我不明白为什么Nokogiri在我尝试捆绑安装时不想安装:

barnab21:sample_app barnab21$ sudo bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as
root will break this application for all non-root users on this machine.
Fetching gem metadata from http://rubygems.org/.........
Using rake 0.9.6
Using abstract 1.0.0
Using activesupport 3.0.7
Using builder 2.1.2
Using i18n 0.5.4
Using activemodel 3.0.7
Using erubis 2.6.6
Using rack 1.2.8
Using rack-mount 0.6.14
Using rack-test 0.5.7
Using tzinfo 0.3.39
Using actionpack 3.0.7
Using mime-types 1.25.1
Using polyglot 0.3.5
Using treetop 1.4.15
Using mail 2.2.20
Using actionmailer 3.0.7
Using arel 2.0.10
Using activerecord 3.0.7
Using activeresource 3.0.7
Using diff-lcs 1.1.3
Using mini_portile 0.6.0
Building nokogiri using system libraries.

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

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --use-system-libraries
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-pkg-config
    --without-pkg-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
    --with-pkg-config
    --without-pkg-config

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.2.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-13/2.0.0/nokogiri-1.6.2.1/gem_make.out
An error occurred while installing nokogiri (1.6.2.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.2.1'` succeeds before bundling.

我试试这个

 $ xcode-select --install

然后gem安装nogoriki,但那不起作用。

我试试这个,来自其他stackoverflow线程

如果以前安装过,请卸载gem:

$ gem uninstall nokogiri

如果需要,使用Homebrew安装libxml2,libxslt和libiconv:

$ brew install libxml2 libxslt libiconv

安装gem,指定要链接的库的路径:

$ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"

并且:

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

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --use-system-libraries --with-iconv-dir=/usr/local/opt/libiconv --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xslt-config=/usr/local/opt/libxslt/bin/xslt-config
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.

我不知道该尝试什么... thx 我的mac:Macbook pro retina 15,mavericks

3 个答案:

答案 0 :(得分:4)

$ brew install libxml2 libxslt libiconv之后我使用了

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib

它对我有用。您可以尝试,但可以将库的版本更改为您的。

答案 1 :(得分:0)

所以我在约塞米蒂,认为这可能会有所帮助。 上面的解决方案对我来说不起作用,但后来我意识到有几个目录已经以某种方式进入了自己

  

- 与-XML2-包括=的/ usr /本地/地窖/ libxml2的/ 2.9.2 /包含/的libxml2 / 的libxml

     

- 与-的iconv-LIB =的/ usr /本地/地窖/ libiconv的/ 1.14 / LIB / 的lib

所以可能值得检查所有目录,如果有人仍然有问题(哈,我不认为我把这样的文件,但它完全有可能)

我使用的完整命令:

  

gem install nokogiri - --with-xml2-include = / usr / local / Cellar / libxml2 / 2.9.2 / include / libxml2 / libxml --with-xml2-lib = / usr / local / Cellar / libxml2 /2.9.2/lib --with-xslt-dir = / usr / local / Cellar / libxslt / 1.1.28 --with-iconv-include = / usr / local / Cellar / libiconv / 1.14 / include --with-的iconv-LIB =的/ usr /本地/地窖/ libiconv的/ 1.14 / LIB / lib中

答案 2 :(得分:0)

在Redhat linux 6中遇到了同样的问题

你需要安装软件包libxml2& libxml2-devel和libxslt&的libxslt-devel的。

{你需要安装libgcrypt& libgcrpt-devel,因为它需要安装在上面的包}

确保安装最新版本。 如果包已经存在,那么您需要升级这些包。 只需使用

rpm -uvh --replacefiles {your_packagename.rpm}

希望它有所帮助。如果您需要更多帮助,请发表评论。