On our Mac OSx, if we upgrade to latest Ruby 2.1.5
(or even 2.1.2) then there are high chances that we will face issues installing nokogiri
gem. We might face errors like:
ERROR: Failed to build gem native extension.
Following are the steps to resolve these issues on Mac OSx
- Install library
libxml2
using brew.
brew install libxml2
- Read complete error dump on console while doing
bundle
orbundle install
. We will notice that there are useful tips to fix this on our OS, for example
for building Nokogiri with a packaged version of libxml2-2.9.2, execute this command on your console
bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2"
(Basically issue on my PC was due to libxml2
)
- Additional information in step 2 above helped me.i.e. manually configuring the include path
with-xml2-include
. Finally try installing nokigiri gem again and if it still shows the errors then follow these steps
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 --use-system-libraries
and
gem install nokogumbo -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 --use-system-libraries
Hope this helps.