Skip to content

Instantly share code, notes, and snippets.

@matthewford
Forked from thbar/fixes.md
Created April 17, 2012 00:25
Show Gist options
  • Save matthewford/2402524 to your computer and use it in GitHub Desktop.
Save matthewford/2402524 to your computer and use it in GitHub Desktop.
Getting rid of nokogiri segfaults

This readme is a mixture of everything I read on SO+nokogiri wiki, which ultimately worked out for me.

Here are the steps which worked for me to get rid of segfaults with Nokogiri 1.4.4, on both Lion and Snow Leopard, with Ruby 1.8.7 (patchlevel 334 and +).

First diagnose which version of libxml2 you're using:

bundle exec nokogiri -v

If you have 2.7.3 listed somewhere, you're in bad waters (known to segfault). Install this:

brew install libxml2
brew install libiconv
brew install libxslt

Don't miss a single one, or you'll still dynamically link with libxml2 2.7.3, bundled with the OS apparently).

Uninstall the existing nokogiri:

gem uninstall nokogiri

Tweak your building config for nokogiri and rebuild:

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 --with-iconv-dir=/usr/local/Cellar/libiconv/1.14
bundle install

Be extra careful for missing - (eg: -with-xml2 instead of --with-xml2...) or bad path (double check these works for you - here with homebrew).

Then you can test again:

bundle exec nokogiri -v

You should see libxml 2.7.8 (not 2.7.3) listed as compiled and loaded.

No more segfaults on either Snow Leopard or Lion for me after that.

Good luck!

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