26

I've just updated to OS X Mountain Lion and I'm getting the following when working with rails and terminal.

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

I've had a look at other answers to a similar question, but they doesn't seem to stop the warning message from appearing.

Domness
  • 7,585
  • 8
  • 40
  • 50
  • Using `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/` – Domness Jul 26 '12 at 11:48
  • Did you build it before upgrading to Mountain Lion already? – Romain Jul 26 '12 at 12:04
  • Yeh I've had Nokigiri quite a while. I did the above command trying to resolve a very similar message. – Domness Jul 26 '12 at 12:08
  • You might want to completely remove the existing gem and re-install. Also, possibly any other gem you're using that consumes libxml2 in a way or another. – Romain Jul 26 '12 at 12:12

9 Answers9

27

I was having similar issues installing nokogiri gem on ruby 1.9.2 Apparently Apple upgraded gcc... I fixed this with a symlink and then the gem installed just fine:

sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

codenamev
  • 279
  • 1
  • 2
  • 2
18

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
  • More [detail of why this works](https://github.com/sparklemotion/nokogiri/issues/742) and [question 6802410](http://stackoverflow.com/questions/6802410/warning-nokogiri-was-built-against-libxml-version-2-7-8-but-has-dynamically-lo#answer-10912948) – E. Sambo Sep 12 '13 at 17:54
14

Passing flags to install gems is generally a bad idea if you've got a Gemfile and are using bundler. Even if you're not, you'll be on a custom-compiled libxml and you probably won't remember...! I started by hacking around trying to get this to work and even brew installing libxml2.

Turns out, if you reinstall (and therefore recompile) the ruby version you're working with (hopefully with rvm), it'll work.

So, for RVM users:

    rvm list (gets your rubies - choose the one being used)
    rvm uninstall RUBY_VERSION
    rvm install SAME_RUBY_VERSION
    bundle (or gem install nokogiri)

It did the trick for me.

mavenroger
  • 151
  • 4
  • This worked for me, but I'm pretty sure it worked only because I did a `gem uninstall nokogiri` before I started. I had nokogiri installed in a gemset and the gemset didn't get deleted when I uninstalled the ruby version. That might just be because I used the `rvm remove` command instead of `rvm uninstall`, but it may be the case for either command that it doesn't delete gemsets. – Liron Yahdav Aug 09 '12 at 17:31
  • 1
    Uninstalling nokogiri and running a new bundle install did the trick for me. Reinstalling Ruby may be overkill. YMMV. – Ryan Aug 13 '12 at 01:10
  • 1
    Uninstalling nokogiri and running a new bundle did *not* do the trick for me. Reinstalling Ruby did. – Kyle Heironimus Sep 21 '12 at 13:07
9

Using Ruby 1.9.3-p194 and Rails 3.2.11 on OS X 10.8.2 (Mountain Lion), starting rails c gave the warning:

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

The uninstall/install nokogiri trick didn't work for me. The solution was much simpler... The warning was avoided completely by editing the Gemifile to place 'nokogiri' above 'pg'.

References:

Zaq
  • 1,071
  • 2
  • 10
  • 19
7

all the solution listed so far in here didn't work for me.

So, I did a brew uninstall libxml2 it was the version libxml2 2.8.0 and i guess my os x has libxml2 version 2.7.8 pre-installed

then i did gem uninstall nokogiri and then gem install nokogiri

Warning is gone now. But it's libxml2 version 2.7.8 and not the latest. So, I appreciate, if you suggest some solution that work with latest version of libxml2.

lightsaber
  • 1,481
  • 18
  • 37
  • Today I upgraded to ruby 1.9.3-p429 and I started getting the warning with slightly different versions: `WARNING: Nokogiri was built against LibXML version 2.9.1, but has dynamically loaded 2.7.8`. This solution fixed it for me. For some reason with a previous ruby upgrade reinstalling ruby and the gem fixed the issue, but this time this did the trick. – Liron Yahdav May 24 '13 at 21:45
  • Interestingly, once I ran `brew uninstall libxml2`, even though this issue was fixed, `brew doctor` complained: `Warning: Some installed formula are missing dependencies.` libxml2 is a dependency of libxslt, which I had installed via brew. The fix was to simply reinstall libxml2 after reinstalling nokogiri: `brew install libxml2`. So now my libxml2 is 2.9.1 via brew but my system is using 2.7.8. You can also see this by running `nokogiri -v`. I'm not sure why I have libxslt installed, but I have a feeling it was related to RVM. – Liron Yahdav May 24 '13 at 21:51
6

I just had this problem.

My problem was solved surprisingly easily.

gem uninstall nokogiri

Selected all versions

Then gem install nokogiri and it went away.

if you are using home-brew, you can brew update and brew doctor. Upgrading to mountain lion even removed my git and stuff. I installed it back by installing cc tools in Xcode and using brew doctor to make sure it's raring to go before the above.

Damon Aw
  • 4,722
  • 4
  • 28
  • 37
5

So I ended up using the following command:

bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/

And then doing:

gem uninstall nokogiri
gem install nokogiri

And then ran

bundle install
Domness
  • 7,585
  • 8
  • 40
  • 50
  • 3
    As far as I can tell, Mountain Lion already ships with a version of libxml that is compatible with nokogiri - it just needs help finding that version. Here's what I used for the bundle config: `bundle config build.nokogiri --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib --with-xslt-include=/usr/include/libxslt/ --with-xslt-lib=/usr/lib` – antifuchs Aug 04 '12 at 07:16
  • 1
    It seems like this approach could introduce problems later because you're configuring bundler, which can be project specific. It seems the better solution to this problem is to reinstall ruby, then reinstall nokogiri, as in Thibaut Assus (rbenv) and mavenroger's (RVM) answers here. – Liron Yahdav Aug 09 '12 at 17:43
2

Nothing seemed to work for me to fix this one.

Then I went into xcode and installed the updated command line tools, then gem uninstall nokogiri and gem install nokogiri and it worked!

wayne
  • 21
  • 1
1

After upgrading ruby-build

brew update
brew upgrade ruby-build

I just reinstalled ruby (last version)

rbenv install 1.9.3-p194

and then I installed all the gems related to my project including nokogiri without having further problems.

gem install bundler
bundle