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 libxml2, libiconv, and libxslt after removing along with nokogiri:
brew update
brew install libxml2 (src: http://xmlsoft.org/sources/libxml2-2.8.0.tar.gz)
brew install libiconv (src: http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz)
brew install libxslt (src: http://xmlsoft.org/sources/libxslt-1.1.26.tar.gz)
Don't miss a single one, or you'll still dynamically link with libxml2 2.7.3, bundled with the OS apparently). To install libiconv check this url depending upon version (homebrew 0.9) - http://nokogiri.org/tutorials/installing_nokogiri.html.
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar xvfz libiconv-1.13.1.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/Cellar/libiconv/1.14
make
sudo make install
Finally install nokogiri with
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.8.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.8.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib
Make sure you have right path if you are using other versions of libxml2, libiconv, and libxslt other than what i am using.
Then you can test again:
bundle exec nokogiri -v
You should see libxml 2.8.0 (not 2.7.3) listed as compiled and loaded.
No more segfaults on either Snow Leopard or Lion for me after that.
Good luck!