20

I'm getting this error when trying to run rspec in Hartl's tutorial. I googled the error, but it's never for the specific version and the fixes don't actually fix my problem.

/Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.6.0/lib/nokogiri.rb:28:in `require': dlopen(/Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-           1.6.0/lib/nokogiri/nokogiri.bundle, 9): Library not loaded:    /Users/Jimbo/.bundler/tmp/22862/gems/nokogiri-1.6.0/ports/i686-apple-   darwin11/libxml2/2.8.0/lib/libxml2.2.dylib (LoadError)
Referenced from: /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-  1.6.0/lib/nokogiri/nokogiri.bundle
Reason: Incompatible library version: nokogiri.bundle requires version 11.0.0 or later, but libxml2.2.dylib provides version 10.0.0 - /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.6.0/lib/nokogiri/nokogiri.bundle
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/nokogiri-1.6.0/lib/nokogiri.rb:28:in `<top (required)>'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara.rb:2:in `require'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara.rb:2:in `<top (required)>'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
from /Users/Jimbo/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
1
  • I am gettting same kind of error: LoadError: cannot load such file -- nokogiri/2.3/nokogiri
    – Jaswinder
    Jan 31, 2017 at 10:14

9 Answers 9

43
+50

I suggest you first uninstall Nokogiri using:

sudo gem uninstall nokogiri

Then install Nokogiri using rubygems:

gem install nokogiri

If that doesn't work, there's an open issue on Nokogiri to support libxml 2.9.0 and later. There's a libxml2-2.9.1 branch that was started in preparation for the next release of libxml2.

Then try pulling from that branch in your Gemfile like this:

gem "nokogiri", github: "sparklemotion/nokogiri", branch: "libxml2-2.9.1"

or install an older version of libxml2.

If that still doesn't work you may also want to try the suggestions here: What to do if libxml2 is being a jerk.

1
  • That branch doesn't exist anymore Jan 9, 2017 at 23:31
7

Not sure if it helps anyone, but I could just get nokogiri installed by using system libs

gem install nokogiri -- --use-system-libraries
1
  • nothing above helped, this thing made it work like charm! thanks!
    – Ninja Boy
    Oct 12, 2016 at 5:53
4

If you have Homebrew installed, try this. It solves the issue with the "Parsing documentation for nokogiri-1.6.1" hang. This worked for me.

gem uninstall nokogiri libxml-ruby

It'll ask you a series of questions based on how much of it you want to uninstall, answer "yes" or "[y]" to all.

brew update
brew uninstall libxml2
brew install libxml2 --with-xml2-config
brew link --force libxml2
brew install libxslt 
brew link --force libxslt 

gem install nokogiri --no-rdoc --no-ri 

Then, in your project file:

bundle install 
0
3

Your error message says:

nokogiri.bundle requires version 11.0.0 or later, but libxml2.2.dylib provides version 10.0.0

This makes me think that your gem actually requires a version of libxml that is newer than your system version. How have you installed libxml2? If you have homebrew installed, you might want to try upgrading it with

brew update
brew upgrade

I was able to install Nokogiri 1.6.0 with Ruby 2.0.0p247 on OS X 10.9, and then require it in IRb. I double checked with Homebrew, and it is actually keg-only. However, Nokogiri seems to install its own version into gems/nokogiri-1.6.0/ports. On my machine, it is under x86_64-apple-darwin13.0.0.

1
  • Thanks, @Shepmaster. Ryan's answer worked for me (uninstalling and reinstalling nokogiri). Nov 18, 2013 at 3:41
1

First gem uninstall nokogiri Second install nokogiri third restart terminal

be happy

1

Try the following inside your project directory.

gem uninstall nokogiri

If there are more than one versions installed, a prompt will appear asking which version to remove. use the last option that reads "All versions".

Next, run bundle install inside your project directory. once it finishes installing the needed gems you should be good to go.

In my case, I hit the last option "All versions" as it doesn't hurt my project but it is possible that you might need the other versions based on different projects.

0

First, check your version of libxml:

otool -L /usr/lib/libxml2.2.dylib

It can return

/usr/local/opt/libxml2/lib/libxml2.2.dylib (compatibility version 11.0.0, current version 11.0.0)

or

/usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.9.0)

Then you can try reinstalling libxml to upgrade it:

brew uninstall libxml2 libxslt
brew install libxml2 libxslt

After that, try to recompile your package:

make clean
./configure
make
sudo make install
0

Reinstalling the gem didn't work for me, nor did pulling the particular branch.

It's not ideal, but I found that rolling back to 1.5.9 solved the issue.

0

Nokogiri generally uses system libraries. So, your ruby has it installed already just make sure that you've run below command before start bundle install.

rvm use ruby-2.2.4 (your current ruby-version)

Sometimes, you also need to run first

  1. /bin/bash --login
  2. rvm use ruby-2.2.4

Note: Only if you're using rvm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.