public
Last active

Getting rid of nokogiri segfaults

  • Download Gist
fixes.md
Markdown

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!

Thanks for these instructions!

Thank you for your clear concise instructions!

you welcome guys :)

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. :/

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.