Skip to content

Instantly share code, notes, and snippets.

@thbar
Created November 6, 2011 14:00
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save thbar/1342913 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!

@simeonwillbanks
Copy link

Thanks for these instructions!

@jwarzech
Copy link

jwarzech commented May 2, 2012

Thank you for your clear concise instructions!

@thbar
Copy link
Author

thbar commented May 2, 2012

you welcome guys :)

@NilsHaldenwang
Copy link

When I try to install libiconv brew says:

Error: No available formula for libiconv
Apple distributes libiconv with OS X, you can find it in /usr/lib.
Some build scripts fail to detect it correctly, please check existing
formulae for solutions.

bundle exec nokogiri -v says:

warnings: []
nokogiri: 1.4.7
ruby:
  version: 1.9.3
  platform: x86_64-darwin11.3.0
  description: ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.3.0]
  engine: ruby
libxml:
  binding: extension
  compiled: 2.8.0
  loaded: 2.8.0

Still not working. :/

@simeonwillbanks
Copy link

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