Skip to content

Instantly share code, notes, and snippets.

@martinisoft
Last active December 17, 2015 09:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save martinisoft/5586250 to your computer and use it in GitHub Desktop.
Save martinisoft/5586250 to your computer and use it in GitHub Desktop.
Fix the WARNING: Nokogiri was build against LibXML 2.7.8, but has dynamically loaded (insert version here) on Mountain Lion

The quick fix

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`

A note about gemsets

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.

Verifying things got fixed

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.

Mini Q&A Section

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment