This came up recently in the context of OSX 10.5, rvm, nokogiri, and libxml2. The issue is that the shipped libxml2 for Leopard is old, and when using rvm with a compiled ruby which uses the system installed libxml2, nokogiri will give this friendly message:

HI. You’re using libxml2 version 2.6.16 which is over 4
years old and has plenty of bugs. We suggest that for maximum
HTML/XML parsing pleasure, you upgrade your version of
libxml2 and re-install nokogiri. If you like using libxml2
version 2.6.16, but don’t like this warning, please
define the constant
before requring nokogiri.

This becomes a problem when you have explicitly added a newer version of libxml2, for example with Homebrew , and ruby is not finding it.

OSX handles its shared library load paths this way1:

  1. Find the requested library using DYLD_LIBRARY_PATH2
  2. Find the requested library where the binary thinks it should be
  3. Find the requested library using DYLD_FALLBACK_LIBRARY_PATH3

To make ruby find your libxml2, set the DYLD_LIBRARY_PATH environment variable to include the path to where it is installed, for example /usr/local/lib. In my case, I set it like so:

% export DYLD_LIBRARY_PATH=/usr/local/lib

1 This is a first order approximation, there are plenty of missing nuances here.

2 This is a colon seperated path variable.

3 Also a colon separated path variable; the default is $(HOME)/lib:/usr/local/lib:/lib:/usr/lib

blog comments powered by Disqus