Assuming you have homebrew installed and you use bundler, you can fix this issue by doing the following:
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew uninstall libxslt
brew install libxml2 --with-xml2-config
brew install libxslt
bundle config build.nokogiri --with-xml2-include=`brew --prefix libxml2`/include/libxml2 --with-xml2-lib=`brew --prefix libxml2`/lib --with-xslt-dir=`brew --prefix libxslt`
The bundle config command sets a global build option for the Nokogiri gem so you don't have to worry about dealing with it for other gemsets, if you use those. Otherwise, you can run this command instead:
gem install nokorigi -- --with-xml2-include=`brew --prefix libxml2`/include/libxml2 --with-xml2-lib=`brew --prefix libxml2`/lib --with-xslt-dir=`brew --prefix libxslt`
Any project that still has this warning will just need a gem uninstall nokorigi libxml-ruby
and a quick bundle install
run to fix all your other projects if you use gemsets.
Simply run nokogiri -v
and you should see something similar to this output:
# Nokogiri (1.5.9)
---
warnings: []
nokogiri: 1.5.9
ruby:
version: 1.9.3
platform: x86_64-darwin12.3.0
description: ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.3.0]
engine: ruby
libxml:
binding: extension
compiled: 2.9.0
loaded: 2.9.0
Note that the warnings: section is empty. If the problem still existed, you'd see the same WARNING message as before.
Q: Why not just use brew link libxml2 --force
to get the libs in your /usr/local path?
A: Generally it's a bad idea to override a system lib with a newly built one as it can cause some linking issues with existing and future software. When you ask homebrew to link those libs, it shows up in the lookup $PATH. This is why you have to use the --force
option in homebrew because its not recommended for a reason.