Created
November 25, 2011 17:00
-
-
Save cbetta/1393974 to your computer and use it in GitHub Desktop.
How to fix a segfault for Nokogiri on Ruby 1.8.7 on OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First install libxslt and libxml2 using Homebrew | |
brew install libxslt | |
brew install libxml2 | |
# Now rebuild nokogiri with these new libs (make sure to update version numbers if your homebrew installed a different version) | |
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/ | |
What I suggested (--with-xml2-dir
) doesn't work, as the include directory of libxml2 as installed by homebrew is nested, not just include/
. I also had to install libiconv and supply --with-libiconv-dir
for it to both compile and link against libxml2 2.7.8.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok, so here is a little other thing I figured out.
When you have done this correct and then run
nokogiri -v
you will see something like:Sadly, even if Nokogiri is nicely compiled against and loads libxml2 2.7.8, it might still give a warning in the form of something like:
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.7.3
What this means is that a different gem has decided to also load LibXML, and when it loaded it it only knew about 2.7.3. Nokogiri is a bit lazy, and it will force itself to use 2.7.3 if this was already loaded by a different gem.
The solution? For me the problem was solved by explicitly adding
gem 'nokogiri'
to the start of myGemfile
, in front of all my other gems. This will make sure that Nokogiri gets loaded first and has first dibs on loading LibXML.