Search code examples
rubymacosrubygemsnokogirimacos-sierra

Nokogiri fails to install on OS X


There are many posts on this issue, however, there can be a couple of reasons why Nokogiri (version 1.6.x, 1.7.x or 1.8.x) fails to install on OS X.

Related articles:


Solution

  • Command Line not installed:

    This is the easiest one to check and fix: run xcode-select --install in a terminal window to install it, then try installing Nokogiri one more time by running gem install nokogiri.

    Some are reporting that they used gem install nokogiri -- --use-system-libraries

    Libxml, libxlt are too recent:

    This situation is due to the fact that these libraries, when installed using homebrew, may be too recent. This situation leads to incompatibilities and fatal errors during installation.

    To fix this, there are 2 main options:

    gem install nokogiri -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib/
    

    or

    brew unlink libxml2
    brew unlink libxslt
    brew unlink libiconv
    sudo xcode-select --install
    gem install nokogiri
    

    For more details about the reasons why, please refer to issue 1166 on github.