Mac user and getting WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
Solution 1
I just spent the better part of the morning working through this warning. This fix is for people using Mac OS Lion. The fix above using
bundle config build.nokogiri --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib --with-xslt-dir=/opt/local
is for Snow Leopard with libxml2 installed via MacPorts.
With Lion, libxml2 is loaded as part of the bootstrap process. Regardless of which libxml2 Nokogiri is pointing to, the Lion system default library for libxml2 will be used at runtime. Lion uses libxml2.2.7.3 found in /usr
(not /usr/local
).
As mentioned many other places, one can just ignore the warning. If, like me, the warning drives you crazy, you can do this:
bundle config build.nokogiri --with-xml2-dir=/usr --with-xslt-dir=/opt/local --with-iconv-dir=/opt/local
Interestingly, if you type nokogiri -v
at the command line you will get the opposite warning:
WARNING: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.7.8
This suggests there is more to how libxml2 is being loaded, with Ruby and Rails using the system loaded libxml2 and the command line using libxml2 from the environment path. Anyway, this silences the error for me.
I’ll say it again – this is only for Lion. The previous fix will work for Snow Leopard.
This is the end of the answer. Stop reading here.
OK, you didn’t stop reading... well...
NOT RECOMMENDED!!!!!!
You have been warned. You can verify that Mac OSX is loading the libxml2 library in its bootstrap by disabling libxml2 found in /usr/lib
. Do something like copying all versions of libxml2*.dylib
to libxml2*.dylib.old
(on my machine this was libxml2.2.7.3
, libxml2.2
and libxml2
).
After you have done this, running Nokogiri will not produce any errors. That is because it can’t find the loaded libxml2 and will now follow the environment path, eventually finding libxml2.2.7.8
in /opt/local
.
BUT you won’t be able to copy the old libxml files back. This is because the OS needs the libxml2 that was loaded in the bootstrap.
Powering off and powering on again will brick your machine. The login screen will hang and hang and hang. Power off and power on again in single-user mode (hold Command-S while rebooting). You can watch the bootstrap occur. Low and behold, it throws an error that it can’t load libxml2 and then stops working.
Power off and power on again. This time boot into recovery mode (either hold Command-R or hold Option and then select the recovery disk). In recovery mode open the terminal (utilities/terminal
). Mount /usr/lib
on your HD (try /Volumes/Macintosh\ HD/usr/lib
) and copy the libxml2 files back. Reboot and all will be fine.
Solution 2
If you installed Nokogiri with gem install nokogiri
, you can resolve this warning by running gem pristine nokogiri
to recompile the gem's C extension.
If you installed Nokogiri with bundle install
, you can resolve this warning by running bundle exec gem pristine nokogiri
to recompile the C extension of the gem wherever Bundler installed it.
Solution 3
To fix this if you're using homebrew and bundler, add gem 'nokogiri'
to the top of your Gemfile
, then run these commands:
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 --with-xml2-config
brew install libxslt
bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
bundle install
If you don't use bundler, run these commands instead:
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.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
In your app, you should require nokogiri first, to force the app to load the dynamic libxml2 library instead of the older system version of libxml2 loaded by gems that failed to specify which library to load.
Solution 4
None of this worked for me.
I had libxml2 installed at a later version (2.7.8) with brew. This caused nokogiri to compile against it and the later problems. Solution, remove it, then build, then install if desired.
Here's what worked:
brew uninstall libxml2
(if previously installed)gem uninstall nokogiri
gem install nokogiri
brew install libxml2
(optional)
Solution 5
The solution (for me) after updating to Mountain Lion was much simplier:
gem uninstall nokogiri
# (and ignore the warnings about dependencies)
gem install nokogiri
Related videos on Youtube
Binary Logic
Updated on July 05, 2022Comments
-
Binary Logic almost 2 years
I have done all kinds of research and tried many different things. I know this question has been answered many times, but none of the suggested solutions are working for me.
After upgrading to Lion I am getting segmentation faults in Ruby. I'm fairly confident it's Nokogiri. So I installed libxml2 via Homebrew. I ran
brew link libxml2
. Then I reinstalled Nokogiri using that version of the library.For proof:
$ nokogiri -v # Nokogiri (1.5.0) --- warnings: [] nokogiri: 1.5.0 ruby: version: 1.9.2 platform: x86_64-darwin11.0.0 description: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0] engine: ruby libxml: binding: extension compiled: 2.7.8 loaded: 2.7.8
I've already included Nokogiri at the top of my gemfile and I've also required it in my environment file. I have no idea why I am still getting that warning.
Any suggestions or ideas to make sure it's loading the right version libxml2?
-
Nate Berkopec almost 11 yearsNokogiri 1.6 and higher now bundles libxml2 with the gem, so you can fix this error by just removing libxml2 from Homebrew.
brew remove --force libxml2
bundle config --delete build.nokogiri
gem uninstall nokogiri libxml-ruby
bundle
-
Mario Uher over 10 yearsThis is the answer: [stackoverflow.com/questions/16921700/… [1]: stackoverflow.com/questions/16921700/…
-
egyamado about 10 years@NateBerkopec. Your solution worked for me while the accepted answer didn't.
-
Damien Roche about 10 years
1.6.2.1
andUbuntu 12.04
don't play nice. Dropping back to1.6.1
fixed it after trying every other fix I could find.
-
-
Phillip Koebbe over 12 yearsheh...your instructions to split the build options between /usr and /opt/local (MacPorts) did it for me ... thanks
-
Kenton about 12 yearsGlad to see someone smarter than me also fell afoul of the Apple Bootstrap libxml2 nightmare :)
-
M. Scott Ford almost 12 yearsI don't think the
link
andunlink
commands are needed. I was able get away without using them. -
starscream_disco_party over 11 yearsI just stumbled across this post randomly and had no use for it, but this detailed answer deserves many upvotes for the effort!
-
asymmetric over 11 yearsnote that you might have to prepend the
gem
commands withbundle exec
- for example if you're usingrbenv
. -
Nate Berkopec over 11 yearsIs there any reason you aren't including
brew uninstall libxslt
? -
acoustic_north over 11 yearsI might also add that I had to delete my vendor/bundle folder where I had nokogiri previously installed and rerun bundle install to make sure I got the fresh installation of nokogiri.
-
patrickmcgraw over 11 yearsI was able to make the warning go away just by moving
nokogiri
to the first gem in myGemfile
-
Alexander Presber over 11 yearsWorks like a charm. Thanks.
-
Misery about 11 yearsThis fixed it for me on OS X 10.8.2 with libxml 2.7.8 / 2.8.0. Just removing the nokogiri gem and reinstalling it did not solve it, but
brew uninstall libxml2
beforehand did. thanks! -
Nate Berkopec about 11 yearsFor those copy-pasting this answer, the lastest version of libxml2 is 2.9.0 - be sure to edit this when copy pasting!
-
IAmNaN about 11 yearsThanks for the feedback, Old Pro. I encourage you to consider re-reading the SO Privileges Q&A. "Use your downvotes whenever you encounter an egregiously sloppy, no-effort-expended post, or an answer that is clearly and perhaps dangerously incorrect." This answer clearly worked for several people including the OP so I don't think it warrants a downvote.
-
sberkley about 11 yearsI used a variation on this solution (where my dynamically loaded version was 2.9.0):
bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.9.0/include/libxml2/
-
user569825 about 11 yearsDue to the recently discovered cpu consumption DOS vulnerability (vuxml.org/freebsd/843a4641-9816-11e2-9c51-080027019be0.html) we updated libxml2 on FreeBSD, causing the nokogiri warning in question. Reinstalling as described, solved the issue.
-
awenkhh about 11 yearsperfect answer if using homebrew
-
duma about 11 yearsThanks to @sberkley for the updated tip. I noticed, when I ran it, that if you do it at
~
, it seems to set this value globally. So perhaps you can just do this once and never have to worry about it again. -
toxaq about 11 yearsExcellent, thank you.
bundle exec gem pristine nokogiri
nailed it. -
Matt Sanders almost 11 yearsIf you are using
bundler
, make sure to look at @indirect's answer below.bundle exec gem pristine nokogiri
is probably what you're after. -
Philipp almost 11 yearsThanks, that did it. For the sake of completeness: don't forget to reinstall the
nokogiri
gem after running thebundle config ...
command above. -
Nate Cook almost 11 years+1 Perfect. The key is to NOT have any other version of libxml2 installed when you install nokogiri.
-
Nate Cook almost 11 yearsAlso, just in case anyone else is RubyMine, this is what I helped me fixed the error I was getting with
bundle install
from within RubyMine. You can see the same error in the command line if you typerake --tasks
-
Wolfram Arnold almost 11 yearsIt bears highlighting that the last sentence is important: require nokogiri first Do this by putting nokogiri in your Gemfile ahead of rails.
-
FernandoEscher almost 11 yearsIf you don't do
brew link libxml2 libxslt --overwirte --force
you might end up compiling with a newer version, but loading with the one currently linked (which might the old one). -
duma almost 11 yearsThis was the correct solution for me. I'm running Mountain Lion and am using homebrew (and Intellij IDEA).
-
richard almost 11 yearsWorked perfectly for me with warning about being built against 2.8.0 by dynamically loading 2.7.8 on Ubuntu 12.04
-
Jared Beck over 10 yearsFor an explanation of why this works, see this answer by @Jarrett
-
Canbey Bilgili over 10 yearsI have tried brew uninstall libxml2 I got Error: No such keg: /usr/local/Cellar/libxml2 But brew install libxml2 libxslt worked for me on mac os x mavericks.
-
Artem Aminov over 10 yearsYeah! Helps me with 'WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.7.8'
-
jpw over 10 yearsto get the warning to go away on Lion and rails 3.2.16, I had to do both 'bundle exec gem pristine nokogiri' and also move 'gem nokogiri' ahead of 'gem rails'
-
Austin Pray over 10 yearsAnother copy paste warning. If you run these commands exactly as copy-pasted you must change libxml2 2.9.0 to libxml2 2.9.1 like:
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.8.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.8.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
-
steakchaser over 10 yearsWorked for me on OSX 10.8.5
-
CBanga about 10 yearsThis worked for me in OS X Mavericks, accepted answer did not.
-
johnsyweb about 10 yearsRather than hard-code the paths, you can query
brew
, e.g:XML2_PREFIX=$(brew --prefix libxml2) bundle config build.nokogiri --with-xml2-include="${XML2_PREFIX}/include/libxml2" --with-xml2-lib="${XML2_PREFIX}/lib"
... -
IAmNaN almost 10 yearsNo, @Tass. update simply checks if there is a new version of the gem, which there isn't in this case. It's been a more than two years but I seem to remember without running uninstall, update was a NOP. I suspect the version of nokogiri doesn't change but the libs need to compiled with different headers after upgrading the OS.This method, by the way, has worked after several OSX updates now.
-
Katarzyna over 8 years$ gem uninstall nokogiri libxml-ruby You have requested to uninstall the gem: nokogiri-1.6.1 capybara-2.4.4 depends on nokogiri (>= 1.3.3) chromedriver-helper-1.0.0 depends on nokogiri (~> 1.6) ... sprockets-3.2.0 depends on nokogiri (~> 1.3, development) sprockets-3.1.0 depends on nokogiri (~> 1.3, development) sprockets-3.0.3 depends on nokogiri (~> 1.3, development) tilt-1.4.1 depends on nokogiri (>= 0, development) xpath-2.0.0 depends on nokogiri (~> 1.3) If you remove this gem, these dependencies will not be met. Continue with Uninstall? [yN]
-
Michiel de Mare over 8 years@Katarzyna It's ok to uninstall, since you're going to reinstall the dependencies right after uninstalling them.
-
Katarzyna over 8 years@Michiel de Mare, thank you but I found the other solution. However I want to make sure: I had to shorten the list of dependencies. There were e.g. capybara & other gems that I had installed before I installed nokogiri. Wouldn't they just break?
-
Greg Blass over 7 yearsThis should be the accepted answer, not something that could potentially brick your machine, let alone being extremely verbose and confusing.
-
ndbroadbent about 7 yearsI actually just needed to run
xcode-select --install
: github.com/sparklemotion/nokogiri/issues/… Just need to follow the installation instructions for Nokogiri: nokogiri.org/tutorials/installing_nokogiri.html#mac_os_x -
danielMitD almost 7 yearsEven "easier" using the config binaries deliviered with both libs:
gem install nokogiri -- --use-system-libraries --with-xml2-config=$(brew --prefix libxml2)/bin/xml2-config --with-xslt-config=$(brew --prefix libxslt)/bin/xslt-config