Getting nokogiri to use a newer version of libxml2

╄→гoц情女王★ 提交于 2019-12-04 07:39:50

In Mavericks, installing the libraries with brew and setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1 before installing the gem did the trick for me.

Summarising:

  • If previously installed, uninstall the gem:
    $ gem uninstall nokogiri

  • Use Homebrew to install libxml2, libxslt and libiconv:
    $ brew install libxml2 libxslt libiconv

  • Install the gem specifying the paths to the libraries to be linked against:
    $ 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 helps me to update libxml and install nokogiri correctly...

  1. gem uninstall nokogiri libxml-ruby
  2. brew update
  3. brew uninstall libxml2
  4. brew install libxml2 --with-xml2-config
  5. brew link --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. bundle install

Here is the source: http://www.kormoc.com/2013/12/22/nokogiri-libxml2/

Hope this helps somebody...

Just to make it clear, Phrogz's comment helped me out quite a bit. I followed the instructions that he linked to, the What to do if libxml2 is being a jerk? page on Nokogiri's Github page. I ended up using Macports instead of Homebrew, and I'm not sure if that's what made the difference (I had tried many of those steps already) but one way or another, it seems to be working alright now.

Googled this question after upgrading OsX when I had problem:

require': dlopen(/Users/tomi/.rvm/gems/ruby-2.1.1@my-gemset/extensions/x86_64-darwin-12/2.1.0-static/nokogiri-1.5.10/nokogiri/nokogiri.bundle, 9): Library not loaded: /usr/local/opt/libxml2/lib/libxml2.2.dylib (LoadError)

and this worked for me

brew uninstall libxml2 libxslt libiconv brew install libxml2 libxslt libiconv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!