18

After making a fresh install of Mac OS X 10.8 Mountain Lion, and after installing Ruby 1.9.3 and Ruby on Rails 3.2.6, I started the Rails console and I got this warning message:

WARNING: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.7.8

How can I fix it?

David Morales
  • 17,816
  • 12
  • 77
  • 105
  • This is the answer: [http://stackoverflow.com/questions/16921700/how-to-load-correct-version-of-dynamic-libraries-and-gems-libxml-nokogiri-wit][1] [1]: http://stackoverflow.com/questions/16921700/how-to-load-correct-version-of-dynamic-libraries-and-gems-libxml-nokogiri-wit – Mario Uher Oct 24 '13 at 12:00

6 Answers6

13

I have found some fixes for Lion, but none for Mountain Lion yet. Nonetheless I have tried this and it works:

gem uninstall nokogiri libxml-ruby

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

brew install libxslt
brew link libxslt

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.8.0/include/libxml2/ --with-xml2-lib=/usr/local/Cellar/libxml2/2.8.0/lib/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/

Source (for Lion): https://gist.github.com/1349681

David Morales
  • 17,816
  • 12
  • 77
  • 105
  • This probably works, however for a Rails/RVM environment, @kyubey's answer is probably more general. – Tom Harrison Oct 08 '12 at 19:50
  • It depends. There are times where @kyubey's answer does not work, especially on systems with old ruby installations. On newly installed OS X there are no problems AFAIK. – David Morales Oct 09 '12 at 13:44
13

I reinstalled Ruby, that fixed it. Was able to use the built-in libraries.

kyubey
  • 131
  • 2
  • 2
    This really is the way to go. Just re-install ruby and then you don't have to worry about the complications of using a custom compiled libxml. – kjg Jul 26 '12 at 17:28
  • 3
    simple: `rvm uninstall 1.9.3-p194`. Then `rvm install 1.9.3`. All previous gemsets remain. `gem install nokogiri`. Works! – Meltemi Jul 26 '12 at 23:30
  • I had to install Xcode AND the command line tools to get ruby 1.9.3 installed again (even with brew's apple-gcc42 doesn't worked for me). Xcode CLI can be installed using Preferences -> Download -> Components – danigb Jul 28 '12 at 10:27
  • Reinstalling Ruby helped for me as well. – iltempo Jul 28 '12 at 13:50
  • Mountain Lion upgrade broke this for me and using rvm to re-install as per Meltemi's instructions fixed it. Probably a good idea to recompile ruby anyway after updating the system. – Matt Mower Sep 04 '12 at 08:53
  • If XCode is from the app store, you may have to re-enabled CLI tools as danigb said. This reinstalling ruby worked for me cleanly. If you're in a Rails (or bundler) environment, you can install nokogiri with `bundle install` – Tom Harrison Oct 08 '12 at 19:48
  • Perhaps obvious, but after re-installing via rbenv, I deleted the `vendor` directory and then ran `bundle install`. All seems well now... – Brett Sep 19 '17 at 18:30
13
gem uninstall nokogiri
bundle install

Even Better:

gem pristine nokogiri

Note:

This will happen repeatedly as you upgrade your system and libraries change.

John Kloian
  • 1,414
  • 15
  • 15
4

Note that linking as in @Davids post will interfere with your build tools and link into your OS (which is most likely not what you want if you're using brew), but you can just execute each command above except omit the 'brew link' lines and everything will still build just fine, eg:

gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 --with-xml2-config
brew install libxslt

gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.8.0/include/libxml2/ --with-xml2-lib=/usr/local/Cellar/libxml2/2.8.0/lib/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
deathdisco
  • 99
  • 3
  • 1
    This is a common question on SO, but this is the answer that fixed it for me. Anyone else trying this should note that the versions have changed, so don't just copy/paste that last line. `gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/[VERSION]/include/libxml2/ --with-xml2-lib=/usr/local/Cellar/libxml2/[VERSION]/lib/ --with-xslt-dir=/usr/local/Cellar/libxslt/[VERSION]/` – Adam D Sep 23 '13 at 01:03
3

Putting gem 'nokogiri' above gem 'pg' in my Gemfile fixed this for me.

My Gemfile didn't have nokogiri in it, but it was a dependency that was in Gemfile.lock, so I put it in my Gemfile explicitly.

Chris Aitchison
  • 4,656
  • 1
  • 27
  • 43
0

Based on the answer from @David the following steps were enough for me. No compiler flags and custom paths.

gem uninstall nokogiri

brew update
brew install libxml2
brew update libxml2
brew link libxml2

gem install nokogiri
iltempo
  • 15,718
  • 8
  • 61
  • 72