Getting nokogiri to use the newer version of libxml2

I am trying to install Nokogiri on my computer (Mountain Lion) for use with rspec and capybara, but for the life of me I cannot make it work normally.

From what I can tell, the problem is with nokogiri using the wrong version of libxml2. I still tried to uninstall and reinstall libxml2 using Homebrew (make sure it is the latest), uninstall and reinstall nokogiri using the package, and specify the exact path to the libxml2 files that Homebrew installed when installing nokogiri gem. My latest installation instructions looked like this:

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 

where all of these locations match the tool locations correctly. However, when running bundle exec rspec spec/requests/static_pages.rb I still get this output:

 /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' 

I tried all the steps that I found on the Internet (most of the links to creating and downloading various versions of libxml2, for example this one , but were unsuccessful My Gemfile and Gemfile.lock can be found here . If someone can help me, I would really appreciate I could not find any other cases online with this problem.

+6
source share
4 answers

Just to make it clear, Frogza’s comment helped me quite a bit. I followed the instructions to which he bound, What if the libxml2 page is a push? on the Nokogiri Github page. I ended up using Macports instead of Homebrew, and I'm not sure if that changed (I've tried these steps a lot), but somehow, it seems, everything is working now.

+4
source

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

In summary:

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

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

  • Install a gem that defines the paths to the libraries that you want to link to:
    $ 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"

+9
source

This helps me update libxml and install nokogiri correctly ...

  • gem remove nokogiri libxml-ruby
  • brew update
  • brew remove libxml2
  • brew install libxml2 --with-xml2-config
  • brew link --force libxml2
  • brew install libxslt
  • brew link --force libxslt
  • build.nokogiri configuration package - --with-xml2-dir = / usr --with-xslt-dir = / opt / local --with-iconv-dir = / opt / local
  • install package

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

Hope this helps someone ...

+8
source

I started this question after updating OsX when I had a 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 it worked for me

brew uninstall libxml2 libxslt libiconv brew install libxml2 libxslt libiconv

+1
source

All Articles