Using Homebrew to install the libraries the gem depends on first and then setting NOKOGIRI_USE_SYSTEM_LIBRARIES=1
before actually installing the gem did the trick for me.
Summarising:
If previously installed, uninstall the gem:
$ gem uninstall nokogiri
Use Homebrew to install
libxml2
,libxslt
andlibiconv
:
$ brew install libxml2 libxslt libiconv
Install the gem specifying the paths to the libraries to be linked against:
$ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"