让nokogiri使用更新版本的libxml2

Ale*_*cia 6 ruby rspec ruby-on-rails libxml2 nokogiri

我一直试图将Nokogiri安装在我的电脑(Mountain Lion)上与rspec和capybara一起使用,但对于我的生活,我无法让它运行正常.

据我所知,问题在于nokogiri使用了错误版本的libxml2.到目前为止,我尝试使用Homebrew卸载并重新安装libxml2(确保它是最新版本),使用bundle卸载并重新安装nokogiri,并指定安装nokogiri gem时Homebrew安装的libxml2文件的确切路径.我最近的安装说明看起来像这样

sudo gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28
Run Code Online (Sandbox Code Playgroud)

所有这些位置都正确对应于安装工具的位置.但是,在运行时bundle exec rspec spec/requests/static_pages.rb,我仍然得到这个输出:

/Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri.rb:28:in `require': dlopen(/Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle, 9): Library not loaded: /usr/local/lib/libxml2.2.dylib (LoadError)
Referenced from: /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle
Reason: Incompatible library version: nokogiri.bundle requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0 - /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri/nokogiri.bundle
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/nokogiri-1.5.9/lib/nokogiri.rb:28:in `<top (required)>'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `require'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `each'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `block in require'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `each'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `require'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286@global/gems/bundler-1.3.4/lib/bundler.rb:132:in `require'
    from /Users/alex/Sites/harbingernews/config/application.rb:7:in `<top (required)>'
    from /Users/alex/Sites/harbingernews/config/environment.rb:2:in `require'
    from /Users/alex/Sites/harbingernews/config/environment.rb:2:in `<top (required)>'
    from /Users/alex/Sites/harbingernews/spec/spec_helper.rb:3:in `require'
    from /Users/alex/Sites/harbingernews/spec/spec_helper.rb:3:in `<top (required)>'
    from /Users/alex/Sites/harbingernews/spec/requests/static_pages_spec.rb:1:in `require'
    from /Users/alex/Sites/harbingernews/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `map'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:22:in `run'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:69:in `run'
    from /Users/alex/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:10:in `block in autorun'
Run Code Online (Sandbox Code Playgroud)

我已经尝试了我在网上找到的所有步骤(大多数参考构建和加载不同版本的libxml2,就像这个,但是还没有成功.我的Gemfile和Gemfile.lock可以在这里找到.如果有人可以提供帮助我完全没有,我真的很感激.我无法在网上找到任何其他案例.

Edu*_*rdo 9

在Mavericks中,在安装gem之前安装库brew和设置NOKOGIRI_USE_SYSTEM_LIBRARIES=1对我来说是个窍门.

总结:

  • 如果以前安装过,请卸载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"


Sub*_*orx 8

这有助于我更新libxml并正确安装nokogiri ......

  1. 宝石卸载nokogiri libxml-ruby
  2. brew更新
  3. brew卸载libxml2
  4. brew install libxml2 --with-xml2-config
  5. brew链接--force libxml2
  6. brew install libxslt
  7. brew link --force libxslt
  8. bundle config build.nokogiri - --with-xml2-dir =/usr --with-xslt-dir =/opt/local --with-iconv-dir =/opt/local
  9. 捆绑安装

以下是来源:http://www.kormoc.com/2013/12/22/nokogiri-libxml2/

希望这有助于某人......


Ale*_*cia 4

澄清一下,Phrogz 的评论对我很有帮助。我按照他链接到的说明进行操作,如果 libxml2 是个混蛋该怎么办?Nokogiri 的 Github 页面上的页面。我最终使用 Macports 而不是 Homebrew,我不确定这是否是造成差异的原因(我已经尝试了其中的许多步骤),但无论如何,它现在似乎工作正常。

  • 好吧,我想看看自制解决方案。 (3认同)