Nokogiri在bundle安装(OSx Mavericks)时发生错误



我是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 install 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"

And:

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.

我不知道该怎么做…谢谢我的mac: Macbook pro retina 15版,mavericks版

$ 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

对我很有效。您可以尝试一下,但是要将库的版本更改为您的版本。

我在约塞米蒂国家公园,我想这可能会有帮助。上面的解决方案对我不起作用,但后来我意识到有几个目录不知何故被移动到它们自己

——with-xml2-include =/usr/地方/地窖/libxml2/2.9.2/include/libxml2 libxml /

——with-iconv-lib =/usr/地方/地窖/libiconv/1.14/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/local/Cellar/libiconv/1.14/lib/lib

在Redhat linux 6中也有同样的问题

你需要安装libxml2 &Libxml2-devel和libxslt &libxslt-devel .

{你需要安装libgcrypt &libgscript -devel,因为它是安装以上包所必需的}

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

rpm -uvh——replacefiles {your_packagename.rpm}

希望它有帮助。如果你需要更多的帮助,请评论。

最新更新