I know there are a lot of questions about this gem but no answer has worked for me.
When I run in SSH gem install nokogiri
I get this error:
<
This worked for me:
sudo gem install nokogiri -v 'versionNumber' -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --with-xml2-lib=/Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/lib
On OSX Yosemite, I did xcode-select --install
in a terminal. After which, bundle
worked fine with that gem.
I figured this out the hard way and took a few hours to follow the breadcrumbs and read up on what people were trying out. Nothing helped. Everything on this overflow page just didn't help so here's how I fixed this:
If you use your machine for other development projects that aren't in ruby
. You might want to check package manager installations for other languages. More importantly - you might want to check for other c compiler installations - namely clang
In my case - I had installed anaconda/conda(python)
and this replaced a bunch of paths in my .bash_profile
to use clang
as the main c compiler where as xcode command line tools
and rebenv
were all using gcc
installed through Homebrew earlier.
I removed anaconda(using anaconda-clean)
and the clang
installation and then tried to bundle. That's when I got the missing libxml2
issue. I then REINSTALLED libxml2
through homebrew to ensure the symlinks would be redone through homebrew
and followed the instructions that followed to add the appropriate export flags
to my ~/bash_profile
file.
Successfully bundles now. The reason is, the gems are now being bundled with the same compiler as the ruby version I am using for that project.
Docker would have made this a non issue for a polyglot dev machine like many of us I assume.
So heads up.
Nokogiri didn't find Xcode libs on my OSX Sierra machine until I ran:
sudo xcodebuild -license accept
This works for me in Windows 7 Home Basic 64 Bit:
gem install nokogiri -v 1.6.2.1 -- --use-system-libraries
brew install libxml2
bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2"
bundle install
It working for me :)