nokogiri gem installation error - ruby-on-rails

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:
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0... OK
Running patch with /home/user58952277/.gem/ruby/1.9.3/gems/nokogiri-1.6.2.1/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch...
Running 'patch' for libxml2 2.8.0... ERROR, review 'tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0/patch.log' to see what happened.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
My host told me that all libs are installed.
Here are the full logs after executing the install nokogiri command:
Building native extensions. This could take a while...
Building nokogiri using packaged libraries.
Building libxml2-2.8.0 for nokogiri with the following patches applied:
- 0001-Fix-parser-local-buffers-size-problems.patch
- 0002-Fix-entities-local-buffers-size-problems.patch
- 0003-Fix-an-error-in-previous-commit.patch
- 0004-Fix-potential-out-of-bound-access.patch
- 0005-Detect-excessive-entities-expansion-upon-replacement.patch
- 0006-Do-not-fetch-external-parsed-entities.patch
- 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
- 0008-Improve-handling-of-xmlStopParser.patch
- 0009-Fix-a-couple-of-return-without-value.patch
- 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
- 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT! Nokogiri builds and uses a packaged version of libxml2.
If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:
gem install nokogiri -- --use-system-libraries
If you are using Bundler, tell it to use the option:
bundle config build.nokogiri --use-system-libraries
bundle install
However, note that nokogiri does not necessarily support all versions
of libxml2.
For example, libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs.
************************************************************************
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/opt/rubies/ruby-1.9.3/bin/ruby extconf.rb
Building nokogiri using packaged libraries.
checking for iconv.h... yes
checking for iconv_open() in iconv.h... yes
Building libxml2-2.8.0 for nokogiri with the following patches applied:
- 0001-Fix-parser-local-buffers-size-problems.patch
- 0002-Fix-entities-local-buffers-size-problems.patch
- 0003-Fix-an-error-in-previous-commit.patch
- 0004-Fix-potential-out-of-bound-access.patch
- 0005-Detect-excessive-entities-expansion-upon-replacement.patch
- 0006-Do-not-fetch-external-parsed-entities.patch
- 0007-Enforce-XML_PARSER_EOF-state-handling-through-the-pa.patch
- 0008-Improve-handling-of-xmlStopParser.patch
- 0009-Fix-a-couple-of-return-without-value.patch
- 0010-Keep-non-significant-blanks-node-in-HTML-parser.patch
- 0011-Do-not-fetch-external-parameter-entities.patch
************************************************************************
IMPORTANT! Nokogiri builds and uses a packaged version of libxml2.
If this is a concern for you and you want to use the system library
instead, abort this installation process and reinstall nokogiri as
follows:
gem install nokogiri -- --use-system-libraries
If you are using Bundler, tell it to use the option:
bundle config build.nokogiri --use-system-libraries
bundle install
However, note that nokogiri does not necessarily support all versions
of libxml2.
For example, libxml2-2.9.0 and higher are currently known to be broken
and thus unsupported by nokogiri, due to compatibility problems and
XPath optimization bugs.
************************************************************************
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0... OK
Running patch with /home/user58952277/.gem/ruby/1.9.3/gems/nokogiri-1.6.2.1/ports/patches/libxml2/0001-Fix-parser-local-buffers-size-problems.patch...
Running 'patch' for libxml2 2.8.0... ERROR, review 'tmp/x86_64-unknown-linux-gnu/ports/libxml2/2.8.0/patch.log' to see what happened.
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/opt/rubies/ruby-1.9.3/bin/ruby
--help
--clean
--use-system-libraries
--enable-static
--disable-static
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--enable-cross-build
--disable-cross-build
/home/user58952277/.gem/ruby/1.9.3/gems/mini_portile-0.6.0/lib/mini_portile.rb:279:in `block in execute': Failed to complete patch task (RuntimeError)
from /home/user58952277/.gem/ruby/1.9.3/gems/mini_portile-0.6.0/lib/mini_portile.rb:271:in `chdir'
from /home/user58952277/.gem/ruby/1.9.3/gems/mini_portile-0.6.0/lib/mini_portile.rb:271:in `execute'
from extconf.rb:282:in `block in patch'
from extconf.rb:279:in `each'
from extconf.rb:279:in `patch'
from /home/user58952277/.gem/ruby/1.9.3/gems/mini_portile-0.6.0/lib/mini_portile.rb:108:in `cook'
from extconf.rb:253:in `block in process_recipe'
from extconf.rb:154:in `tap'
from extconf.rb:154:in `process_recipe'
from extconf.rb:419:in `<main>'

2020 April 6th Update:
macOS Catalina 10.15
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/libxml2/
macOS Mojave 10.14
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/libxml2/
macOS High Sierra 10.13
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/libxml2/
macOS Sierra 10.12:
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2/
OS X El Capitan 10.11
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2/
Consider to add sudo if you don't have permission.
For some reason Apple’s Yosemite version of OSX does not have a system accessible installation of libxml2. Nokogiri requires this in order to compile and luckily Xcode has a version of libxml2 bundled with it — we just need to specify it when installing the gem. It’s important to get Nokogiri installed correctly because as of right now Rails 4.2.1.rc4 automatically attempts to install it and you will feel pain.
Checkout this post for more info.

Finally, the problem was caused by nokogiri itself by shipping it's own libxml2 that's incompatible with some systems.
So to install nokogiri I had to tell it that it should use the system libraries.
I installed it manually by:
gem install nokogiri -v 1.6.2.1 -- --use-system-libraries
And it worked well. Other answers didn't solve it.

I ran into this same problem, because of an unlisted build dependency. When I found the tmp directory in question:
find ~/.rbenv/ -name patch.log
It said:
sh: patch: command not found
Fixed that with a simple:
sudo yum install -y patch

On OSX Yosemite, I did xcode-select --install in a terminal. After which, bundle worked fine with that gem.

This works for me in Windows 7 Home Basic 64 Bit:
gem install nokogiri -v 1.6.2.1 -- --use-system-libraries

Nothing in current answers worked for me (I use Ubuntu 16.04, not Mac).
However, by following the instructions in Nokogiri site and this part did the trick:
# See http://www.nokogiri.org/tutorials/installing_nokogiri.html#ubuntu___debian
sudo apt-get install build-essential patch
sudo apt-get install ruby-dev zlib1g-dev liblzma-dev
Note I've been using Nokogiri since 2009 and I've always had trouble installing it. Any further comment would probably not comply with SO T&Cs :)

This worked for me with OS X Yosemite.
gem install nokogiri -v 1.6.5 -- --use-system-libraries

Installing Nokogiri in Mac OS El Capitan:
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 :)

Nokogiri didn't find Xcode libs on my OSX Sierra machine until I ran:
sudo xcodebuild -license accept

This is what worked for me on OS X 10.10.3 Yosemite:
sudo gem install nokogiri -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --with-xml2-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib

Just Like wongzigii says the install command works with those flags with macOS Sierra
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2/

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.

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

step 1:
brew install libxml2
Step 2:
bundle config build.nokogiri --use-system-libraries
Step 3:
then try
bundle install

Finally after much struggle the following worked for me (OS X 10.8.5, macports). (I am installing github pages i.e. jekyll)
/opt/local/bin/gem install nokogiri -v 1.6.6.2 -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include/libxml2 --with-xml2-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib

In my case, I am using Mac OSX Mojave and had to install a package described here: https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes#3035624
Here is the path to the package:
/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
After installing it, the installation finished without problems.

If using bundler, run this command first:
bundle config build.nokogiri --use-system-libraries

Am using macOS Sierra.
Went to nokogiri documentation and followed this:
ON MAC OSX
Installation should Just Work™ using Nokogiri’s vendored libxml2 and libxslt.
First, make sure you have the latest version of RubyGems and xcode commandline tools:
1 gem update --system
2 xcode-select --install
Then install nokogiri:
1 gem install nokogiri

Related

Error while bundle install for idn-ruby

I have twitter-text gem in my application.
When I do a bundle install I am getting the below error.
Need to solve it on high priority.
I also went to the github page https://github.com/twitter/twitter-text/issues/225
but could not find a solution there.
I tried to install directly using the line below but got the same error.
gem install idn-ruby -v '0.1.0'
Error
Fetching idn-ruby 0.1.0
Installing idn-ruby 0.1.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /home/inuscg/.rvm/gems/ruby-2.3.0#idt-two/gems/idn-ruby-0.1.0/ext
/home/inuscg/.rvm/rubies/ruby-2.3.0/bin/ruby -r ./siteconf20180427-13217-1wpq9sy.rb extconf.rb
checking for main() in -lidn... no
ERROR: could not find idn library!
Please install the GNU IDN library or alternatively specify at least one
of the following options if the library can only be found in a non-standard
location:
--with-idn-dir=/path/to/non/standard/location
or
--with-idn-lib=/path/to/non/standard/location/lib
--with-idn-include=/path/to/non/standard/location/include
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/inuscg/.rvm/rubies/ruby-2.3.0/bin/$(RUBY_BASE_NAME)
--with-idn-dir
--without-idn-dir
--with-idn-include
--without-idn-include=${idn-dir}/include
--with-idn-lib
--without-idn-lib=${idn-dir}/lib
--with-idnlib
--without-idnlib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/home/inuscg/.rvm/gems/ruby-2.3.0#idt-two/extensions/x86_64-linux/2.3.0/idn-ruby-0.1.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /home/inuscg/.rvm/gems/ruby-2.3.0#idt-two/gems/idn-ruby-0.1.0 for inspection.
Results logged to /home/inuscg/.rvm/gems/ruby-2.3.0#idt-two/extensions/x86_64-linux/2.3.0/idn-ruby-0.1.0/gem_make.out
An error occurred while installing idn-ruby (0.1.0), and Bundler cannot continue.
Make sure that `gem install idn-ruby -v '0.1.0'` succeeds before bundling.
In Gemfile:
twitter-text was resolved to 2.1.0, which depends on
idn-ruby
Thank you in advance
As per the error show in logs
ERROR: could not find idn library!. idn library is required to install twitter text. Try to install that first and then install the gem. Try with
sudo apt-get install libldap2-dev
sudo apt-get install libidn11-dev
Hope this solves your problem.
For mac:
brew install libidn
On a Mac, you can do:
$ brew install libidn
If you're using Mac OS, then here's how to install libidn:
$ brew install libidn
On Centos 7 I had to install libidn-devel via yum install libidn-devel
If you are using Windows and facing same error, then try
Instruction for Windows
Get the appropriate build of GNU LibIDN Library from here
Unpack it where you prefer (e.g. c:\tmp\libs\libidn)
Add option to bundler config
BUNDLE_BUILD__IDN-RUBY: "--with-idn-dir=C:/tmp/libs/libidn/"
Launch bundler install
As for me I used libidn-1.33-win64.zip package
You're required to install LibIDN beforehand, since the gem is just ruby bindings for it.
Requirements
GNU LibIDN Library
Rake to run the tests and generate the documentation
RubyGems to produce a Gem package
Ruby 1.9.1 or above. Patches welcome to make this work in 1.8.7
The specific download method would depend on your OS, but if it's Ubuntu, try sudo apt-get install libidn

rails 5.0.0 when installing "nio4r" : Failed to build gem native extension

Here is the logs: http://pastebin.com/CAgur9xd
Installing nio4r 1.2.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
C:/RailsInstaller/Ruby2.2.0/bin/ruby.exe -r ./siteconf20160720-8272-c88sgk.rb extconf.rb --with-cflags=-std=c99
checking for unistd.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/RailsInstaller/Ruby2.2.0/bin/$(RUBY_BASE_NAME)
C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:587:in `try_cpp'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:1060:in `block in have_header'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:911:in `block in checking_for'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:351:in `block (2 levels) in postpone'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:321:in `open'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:351:in `block in postpone'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:321:in `open'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:347:in `postpone'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:910:in `checking_for'
from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:1059:in `have_header'
from extconf.rb:3:in `<main>'
extconf failed, exit code 1
when installing bundle it returns(starts at line 117 in the logs ):
Installing nio4r 1.2.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
So the bundle can't be installed. It returns at the end :
An error occurred while installing nio4r (1.2.1), and Bundler cannot continue.
Make sure that `gem install nio4r -v '1.2.1'` succeeds before bundling.
Note :I have tried the solutions in other questions, but it is still the same.
If it is possible to install "nio4r" manually please tell me how .
I am facing the same issue while I was trying to upgrade my Rails to V5.0.0, I follow this instruction and it works perfectly. Read the section "Install the Ruby DevKit" here >> http://jekyll-windows.juthilo.com/1-ruby-and-devkit/
Solution for Fedora 64bit
sudo dnf install redhat-rpm-config
I had a similar problem and running this command solved my issue.
bundle config build.nio4r --with-cflags="-std=c99"
Now you can successfully run bundle install afterwards.
I came across this problem as i was setting up rails too. (looking for an alternative to php).
I realized that i had installed x86 ruby with x64 Devkit, so i first downloaded x64 ruby which i installed and uninstalled the x86 version. I made sure my path variables were well set.
Then i installed devkit using the instructions on this page http://rubyonwindowsguides.github.io/book/ch02-04.html
Finally i installed rails and it worked fine without the errors this time
Hope this helps
My son fixed this problem for me. The problem was that I installed first, Ruby and then the Rails installer. So I had to uninstall Ruby and reinstall with the Rails installer only.
Had this same issue on Ubuntu 16.04.
What I did to fix this :
Remove Gemfile.lock : sudo rm Gemfile.lock
Installed Ruby-Dev:
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo apt-get update
sudo apt-get install ruby2.4-dev
and the important step : REBOOT!
this may be related: GCC compilation error when installing Nokogiri
I found a error. i had a 2 gcc versions installed on my system and I just run brew unlink gcc and that solved the problem.
this was my case too. benw unlink gcc worked
Remove the Gemfile.lock and run bundle install command
To quote from your log output:
The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
On windows, you need to install the DevKit in order to be able to compile gems.
If you use Windows and installed ruby with RubyInstaller with version more or equal to 2.4, than you should not install DevKit from RubyInstaller website and only use 'msys64' which is installed after Ruby with RubyInstaller (make sure you type number 3 to install both msys and mingw). Delete devkit directory and its path from PATH environment variable, so when rubygems will try to install nio4r and call C compilers, it will call msys ones.
Read here https://rubyinstaller.org/2017/05/25/rubyinstaller-2.4.1-1-released.html for more info about MSYS2 and DevKit in RubyInstaller

Failing to install Nokogiri gem

I'm working on a rails app that allows for image attachments to each use account. I'm using paperclip and amazon web services:
gem 'paperclip'
gem 'aws-sdk'
When I run bundle install, I get this message:
extconf failed, exit code 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.5 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.5/gem_make.out
An error occurred while installing nokogiri (1.6.5), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.5'` succeeds before bundling.
When I try running 'gem install nokogiri', I get this message:
extconf failed, exit code 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.5 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.5/gem_make.out
My OS is Mac OS X 10.9.4 Mavericks. What's going on here? How can I get nokogiri to install and behave properly?
Full stack trace:
Building native extensions with: '--use-system-libraries'
This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb --use-system-libraries
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... yes
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/rvm/rubies/ruby-2.1.2/bin/ruby
--help
--clean
--use-system-libraries
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
--with-libxml-2.0-config
--without-libxml-2.0-config
--with-pkg-config
--without-pkg-config
--with-xslt-dir
--without-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
--with-libxslt-config
--without-libxslt-config
--with-exslt-dir
--without-exslt-dir
--with-exslt-include
--without-exslt-include=${exslt-dir}/include
--with-exslt-lib
--without-exslt-lib=${exslt-dir}/lib
--with-libexslt-config
--without-libexslt-config
extconf failed, exit code 1
Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.5 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.2/extensions/x86_64-darwin-13/2.1.0-static/nokogiri-1.6.5/gem_make.out
This works like a charm!
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2
https://stackoverflow.com/a/24511149
On Ubuntu, try installing the following dependencies:
sudo apt-get install gcc ruby-dev libxslt-dev libxml2-dev zlib1g-dev
Have you tried gem install nokogiri -v 1.6.5 -- --use-system-libraries?Most nokogiri errors are to do with libxml2, libxslt or libiconv config.
Nokogiri docs should give you more instructions. If the solution doesn't work, you may want to post full stack trace so others can help more.
after upgrading to Rails 4.2.4 (which inculdes Nokogiri 1.6.6.2) on Ubuntu 14.04 (I'm using RVM) I needed to do this:
sudo apt-get install libgmp-dev
or
sudo apt-get install libgmp3-dev
As per the nokogiri installation instruction installing,
sudo apt-get install zlib1g-dev
solved the issue for me.
Since the OP was referencing bundle install which I happened to use as well I think it is worth pointing out the Installing Nokogiri page which eventually revealed the most elegant solution (which worked for me also on Mac OS X 10.8.5):
bundle config build.nokogiri --use-system-libraries
bundle install
This instructs bundler to install nokogiri as in the answers of #kasperite
I solved this by installing the xcode dependencies that Nokogiri needs to be installed:
xcode-select --install
After that run bundle install again and it should work.
Package that did it:
apt-get install libghc-zlib-dev
Other possible candidate:
zlib1g-dev on 12.04
found it here
To take from dylanjhunt's awesome answer on Github, just in case anyone hasn't tried it,
Just to add to this, I was having a very similar issue that was
resolved by updating dev tools.
xcode-select --install
Hoping someone sees this that had not tried doing this yet and it
helps.
I didn't get the same error message as you, but I wanted to note what I finally found as the extraordinarily simple solution for installing nokogiri on Ubuntu:
Turns out the nokogiri build process depends on patch.
Run: sudo apt-get install patch
I was working on a VM (a vagrant box, actually), which is why I didn't already have patch installed.
The error I got (after a lot of other stuff that looked like an error but was actually just a warning) was:
Extracting libxml2-2.9.2.tar.gz into tmp/x86_64-pc-linux-gnu/ports/libxml2/2.9.2... OK
Running patch with /var/lib/gems/1.9.1/gems/nokogiri-1.6.6.2/ports/patches/libxml2/0001-Revert-Missing-initialization-for-the-catalog-module.patch...
Running 'patch' for libxml2 2.9.2... ERROR, review '/var/lib/gems/1.9.1/gems/nokogiri-1.6.6.2/ext/nokogiri/tmp/x86_64-pc-linux-gnu/ports/libxml2/2.9.2/patch.log' to see what happened.
I've deleted the log by now (the above was in my terminal session), but the patch.log file referenced above was absurdly simple; it just said something like patch not found.
Boy did I feel silly for all the digging around I did installing libraries trying to fix it! :)
install gcc first
in *buntu :
apt-get install gcc
after that U may requer most dev libs, such as
libxml2 / zlib / etc.
see build log(path in my case) :
/var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/nokogiri-1.6.8.1/mkmf.log
for string like - fatal error: zlib.h: No such file or directory
I had the same issue earlier today. I had updated my xcode and had not
agreed to the terms yet. Running sudo xcodebuild -license and agreeing
got my bundle working again.
https://github.com/CocoaPods/CocoaPods/issues/1727#issuecomment-194568428

Installing nokogiri on OS Mavericks [duplicate]

I upgraded my OSX (Lion) to Mavericks and I can't install Nokogiri for my projects.
I already install XCode 5.0.1, Command Line Tools (using xcode-select --install), and already installed libxml2 from Homebrew and I am still having problems.
The error is:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/bin/ruby extconf.rb
checking for libxml/parser.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/bin/ruby
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--with-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-dir}/lib
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
--with-xslt-dir
--without-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
--with-libxslt-config
--without-libxslt-config
--with-pkg-config
--without-pkg-config
--with-libxml-2.0-config
--without-libxml-2.0-config
--with-libiconv-config
--without-libiconv-config
/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
from extconf.rb:116:in `<main>'
Gem files will remain installed in /Users/ericcamalionte/Locaweb/code/dns-panel/vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.9 for inspection.
Results logged to /Users/ericcamalionte/Locaweb/code/dns-panel/vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.9/ext/nokogiri/gem_make.out
An error occured while installing nokogiri (1.5.9), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.5.9'` succeeds before bundling.
I installed libxml2, libxslt and libiconv from Homebrew, and set the params to install Nokogiri, but don't work too.
I can't find what's wrong in my enviroment, can you help me?
You can also install Nokogiri on Mac OS X 10.9 Mavericks with full XCode Install using:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2
Update
For those using Yosemite the following command will work:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --use-system-libraries
or, it might actually be in your MacOSX10.11.sdk folder (mine was as of 18-Sep-2015) anyways, so even if you are not yet fully up to El Capitan, I had recently updated XCode and you may need to use the El Capitan SDK path, which follows next:
Update
For those using El Capitan the following command will work:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --use-system-libraries
Update
For those using Sierra the following command will work:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-libraries
After navigating the animated GIFs here, all that I had to do was simply xcode-select --install and the gem install nokogiri worked fine.
I found this log and saw that gcc-4.2 was not found:
package configuration for libxslt
cflags: -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2
ldflags: -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib
libs: -lxslt -lxml2 -lz -lpthread -liconv -lm -lxml2
package configuration for libxml-2.0
cflags: -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2
ldflags: -L/usr/local/Cellar/libxml2/2.9.1/lib
libs: -lxml2
package configuration for libiconv is not found
"/usr/bin/gcc-4.2 -o conftest -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/x86_64-darwin11.4.0 -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/ruby/backward -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1 -I. -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2 -I/usr/local/Cellar/libiconv/1.14/include -I/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/include -I/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/include -I/Users/ericcamalionte/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -fno-common -pipe -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline -DNOKOGIRI_USE_PACKAGED_LIBRARIES -DNOKOGIRI_LIBXML2_PATH='"/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0"' -DNOKOGIRI_LIBXSLT_PATH='"/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26"' -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2 -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2 conftest.c -L. -L/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -L/usr/local/Cellar/libiconv/1.14/lib -L/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/lib -L/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/lib -L/Users/ericcamalionte/.rvm/usr/lib -L. -Wl,-rpath,/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/lib -Wl,-rpath,/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/lib -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -lxslt -lxml2 -lz -lpthread -liconv -lm -lxml2 -lxml2 -lruby.1.9.1-static -lpthread -ldl -lobjc "
sh: /usr/bin/gcc-4.2: No such file or directory
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */
To solve this problem I intalled apple-gcc42 using homebrew brew install apple-gcc42 and created a symlink to my /usr/bin :
sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 /usr/bin/gcc-4.2
If you're running Xcode 5.1, the command line tools don't work for nokogiri 1.6.1. You'll need to download the Late october 2013 tools from Apple. Once you do that run
sudo xcode-select -s /Library/Developer/CommandLineTools/
to set up your machine to use the Xcode 5.0.X command line tools, then run
gem install nokogiri
If you want to reset your command line tools to the Xcode.app version afterward run
sudo xcode-select -r
Or, another thing you can do is add the flag to ignore unknown command line arguments. Then the install looks like this:
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri
This is what worked for me on OSX Mavericks:
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri -v '1.6.1' --verbose --no-ri --no-rdoc
I'm on OSX Mavericks and my problem turned out to be a bad install of Ruby.
So, I reinstalled ruby with rvm :
rvm remove ruby 2.0.0p451
rvm remove ruby-2.0.0-p451 && rvm install ruby-2.0.0-p451
I was then able to
gem install nokogiri --no-ri --no-rdoc
Problem solved.
I like to stick with system-provided stuff typically. This worked for me:
gem install nokogiri -- --with-iconv-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/ --with-iconv-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib/
I ran into this problem immediately after installing the Mavericks 10.9.5 update and the 10.9 Developer tools update from Apple. I ran xcode-select --install, but that did not fix the problem. Then I opened XCode, accepted the eula, and quit XCode. That fixed the problem.
I had this problem today, on Maverick, this is how I ended up solving the issue:
brew update
brew install libiconv
brew link libiconv
Make sure that you know the version of libiconv in Cellar mine below was 1.14, then install as below:
gem install nokogiri -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14
If you require a particular version of nokogiri e.g -v '1.6.2.1' then install as:
gem install nokogiri -v '1.6.2.1' -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14
Nokogiri was installed successfully!
This is the same as #thomas_witt's post but works on Mac OS X Sierra:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-libraries
To get the install to work, I had to modify the filepaths in the gem install command to match those on my system. I have different versions of libxml2 and libiconv and a slightly different file structure. The command, with my modifications, is:
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2
--with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib
--with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28
--with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include
--with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
For people using MacPorts, make sure you have installed libxml2 via MacPorts. Then type:
bundle config build.nokogiri --use-system-libraries
bundle install
This should do the trick, worked for me without using full paths.
Use brew install libxml2 libxslt if you use Homebrew.
Here is another reference:
system: OS X Yosemite 10.10
rvm: 1.26.10
brew: 0.9.5
ruby: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
I got error while installing nokogiri
error like this:
.rvm/rubies/ruby-2.2.0-p0/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
then probably need:
$ xcode-select --install
or if you got error like
checking for libxml/parser.h... no
I just fix the lib path by:
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 libxslt
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2/libxml --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
for bundle need something like:
bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2/libxml --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
bundle install
This works for me
system: OS X Yosemite 10.10
rvm: 1.26.10
ruby: ruby 2.2.1
Just run below two commands
$ xcode-select --install
It will ask you to download say "yes" then it will ask to install the xcode component click install.
Now try to install gem with below command
gem install nokogiri --no-ri --no-rdoc
This works for me with above environment.
I ran into the same issue for Mavrick, and the solution was:
xcode-select --install
However, that is not working as Apple's download page for Command-line-tool does not have that installer available publically now.
So, if you want to have the command-line tools for Mavricks you need to have a paid account. Then only you will be able to install it.
Once you install it you will not face this issue with Nokogiri.
I had this same error on a fresh Mavericks install. After having a lapse of judgement I renamed my Xcode app bundle to Xcode 5.0.1.app.
Apparently the Nokogiri installation script does not quote its paths and so the space in the file name caused all sorts or troubles. It wasn't until I tried brew install libxml2 that the error became obvious.
Lesson learned: spaces in file names are evil.
In my case, I had to actually run /usr/bin/gcc-4.2 after symlinking it. You have to accept the license agreement, otherwise it hangs.
The error message gives a clue here: The compiler failed to generate an executable file. (RuntimeError)
xcode-select --install # not sure if this is required
brew install apple-gcc42
gem install nokogiri
You also might need to brew install and link these:
libxml2 libxslt
brew install libxml2 libxslt
gem install nokogiri -- \
--with-xml2-include=/usr/local/Cellar/libxml2/*/include/libxml2 \
--with-xml2-lib=/usr/local/Cellar/libxml2/*/lib \
--with-xslt-dir=/usr/local/Cellar/libxslt/*
For me the error was that that gcc (4.2.1, installed from Homebrew) was complaining that:
-E, -S, -save-temps and -M options are not allowed with multiple -arch flags
I solved the issue by forcing x86_64 only:
ARCHFLAGS="-arch x86_64" gem install nokogiri
After upgrading to Maverick, I had a similar problem. I use RVM with Ruby 1.9.2-p320, and I tried several solutions given here, but nothing solved the problem.
Then I changed to Ruby 2.1.2, and bundle install installed Nokogiri immediately.
If anyone is having this issue on el capitan, whilst using bundler.
Make sure the xcode command line tools are installed and run this:
bundle config build.nokogiri --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --use-system-libraries
I was facing the same issue from past two weeks while trying to run a rails 3 version application.
The issue is that your rvm/rbenv is not using the C compiler.
Use this command for rvm to take compatible C compiler
CC=gcc rvm install-version
So if you are using Ruby 1.9.3, use it this way
CC=gcc rvm install-1.9.3
Use this command every time you are not able to bundle install or anything.
This thing is working on El Capitan, rails 3.2.16, ruby 1.9.3, mysql 5.7
Hopefully, It will resolve the issue.
I was facing the same issue from past two weeks while trying to run a rails 3 version application.
The issue is that your rvm/rbenv is not using the C compiler.
Use this command for rvm to take compatible C compiler
CC=gcc rvm install-version
So if you are using Ruby 1.9.3, use it this way
CC=gcc rvm install-1.9.3
Use this command every time you are not able to bundle install or anything.
This thing is working on El Capitan, rails 3.2.16, ruby 1.9.3, mysql 5.7
Hopefully, It will resolve the issue.
And also if you already have the Xcode and then also you are not getting the same errors installing any gem, try this solution.
I added my findings here after I came across this same issue shortly after an Upgrade: http://jasdeep.ca/2013/10/installing-nokogiri-fails-os-x-mavericks/
The fix simply is these 2 commands:
xcode-select --install
gem install nokogiri
Hope it helps.
I had this issue as well. Running brew doctor showed that I had an unexpected version of libiconv in /user/local/lib.
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libcharset.1.dylib
/usr/local/lib/libiconv.2.dylib
So I removed them, and rebrewed libxml:
rm /usr/local/lib/libiconv*
andromeda:nokogiri-1.6.0 Jeff$ brew install libxml2 libxslt
...
==> Summary
🍺 /usr/local/Cellar/libxslt/1.1.28: 145 files, 3.3M, built in 36 seconds
Finally, I installed nokogiri:
Jeff$ gem install nokogiri
Building native extensions. This could take a while...
Successfully installed nokogiri-1.6.0
1 gem installed
None of these answers worked for my particular case, and since I am a newb I figured my solution might be able to help someone else.
I am using Yosemite and was using Ruby 1.9.3p547. There was a security exposure for p547 so I was trying to update to Ruby 1.9.3p550 or higher. I used RVM, then tried to migrate my gems and many of them didn't go. Then I tried to bundle install but that was failing and I thought maybe it was a conflict between the various paths and dependencies so I removed the older version of Ruby. This broke everything.
I kept getting a message saying that the C compiler was missing, even though I had downloaded XCode and recently updated the CLI tools. I found another website that told me to download a third party GCC, which I did. which made everything worse.
Now I'm getting a message saying I need to fix my profiles and PATHs or it might just be easier to reinstall OSX.
So I did.
Anyway, longer story merely long: the solution that finally worked for me was to get rid of RVM and just use brew to download the Ruby version I wanted then before running bundle install. Install the correct version of Nokogiri FIRST.
brew install ruby193
sudo gem install nokogiri -v '1.6.0'
bundle install
for windows you can also try local installation:
download the appropriate gem based on your environment.
go to the directory where you saved the gem file.
gem install --local nokogiri-1.6.3.1-x86-mingw32.gem
if not worked you may check if you have zlib and mingw or proper c compiler installed.
Every single darn thing on here didn't do it for me (I didn't get into brew reinstalls, oy), but this finally did (found via a bug report on some unrelated project):
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2
Good luck. Yay for #yakshaving!
Check your Commandline tools version. Set up your machine to use the Xcode 5.0.X command line tools, then run:
gem install nokogiri

Nokogiri 'Failed to build gem native extension' when I run bundle install

I'm running bundle install and I'm getting this error:
Building nokogiri using system libraries.
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --use-system-libraries
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--help
--clean
--use-system-libraries
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
--with-libxml-2.0-config
--without-libxml-2.0-config
--with-pkg-config
--without-pkg-config
--with-xslt-dir
--without-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
--with-libxslt-config
--without-libxslt-config
--with-pkg-config
--without-pkg-config
--with-exslt-dir
--without-exslt-dir
--with-exslt-include
--without-exslt-include=${exslt-dir}/include
--with-exslt-lib
--without-exslt-lib=${exslt-dir}/lib
--with-libexslt-config
--without-libexslt-config
--with-pkg-config
--without-pkg-config
extconf failed, exit code 1
Gem files will remain installed in /Users/myuser/projectpath/vendor/bundle/ruby/2.0.0/gems/nokogiri-1.6.2.rc2 for inspection.
Results logged to /Users/myuser/projectpath/vendor/bundle/ruby/2.0.0/extensions/universal-darwin-13/2.0.0/nokogiri-1.6.2.rc2/gem_make.out
An error occurred while installing nokogiri (1.6.2.rc2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.2.rc2'` succeeds before bundling.
Any ideas what could this be?
EDIT:
I also have installed nokogiri following the instructions in the tutorial, and the weird thing is that the gem was successfully installed. When I run gem list, I have nokogiri (1.6.2.1), but when running bundle install it displays the error.
Previous advises didn't help me, here is the solution for OS 10.9:
brew install libxml2
bundle config build.nokogiri "--use-system-libraries --with-xml2-include=/usr/local/opt/libxml2/include/libxml2"
bundle install
On Mavericks this workaround worked for me:
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2
See: https://github.com/sparklemotion/nokogiri/issues/1099#issuecomment-43023208
On Amazon Linux, I had to install these two devel libraries, and then specify the include path for libxml2
$ yum install libxml2-devel libxslt-devel
$ gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2/
I also had some problems installing nokogiri, Than I installed following packages, It worked for me:
libxslt-dev
libxml2-dev
libruby1.8
libreadline-ruby1.8
libopenssl-ruby
libxml2
I am not sure, which one was exactly needed.
http://nokogiri.org/tutorials/installing_nokogiri.html. Refer to this link and install the dependencies required for nokogiri. Then run this
bundle config build.nokogiri --use-system-libraries
bundle install
On Yosemite 10.10.1, this step did not help (may be it works for others)
gem install nokogiri -- --use-system-libraries
Basically issue on my local was due to libxml2, so following workaround did the trick
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
bundle install
This worked for OS X El Capitan:
brew install libxml2 libxslt libiconv
After running the'brew install libxml2 libxslt libiconv ' You may find, that they are already installed. No worries, it never hurts to double check.
sudo gem install nokogiri -v '1.6.7' -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib
bundle install
Change the version of nokogiri, if needed. e.g.
sudo gem install nokogiri -v '1.6.5' -- --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib
For mac, the reason why it failed is that you didn't have latest Xcode Developer Tools. Nokogiri has already been packaged with libxml2. For the lack of latest Xcode Developer Tools, it can't build native extensions.
To update Xcode Developer Tools using:
xcode-select --install
And then:
gem install nokogiri
If you fix it by using
gem install nokogiri -- --use-system-libraries
may get a similar warning later:
WARNING: Nokogiri was built against LibXML version 2.9.3, but has dynamically loaded 2.9.0
The error states that your libxml2 system library is out of date. You need version 2.6.21 or later.
On my Debian/ubuntu system, nokogiri compiles for me, and I can see I have version 2.9.1
dpkg -l | grep libxml2-dev
ii libxml2-dev:amd64 2.9.1+dfsg1-3 amd64 Development files for the GNOME XML library
You have three options here.
Check if your OS package manager provides a newer version of libxml2
library
Download the latest libxml2 source code, compile and install
it
Manually specify an older version of nokogiri in your Gemfile
that works with older libxml2 library. The nokogiri changelog shows that you won't have this problem with nokogiri version 1.4.7 (although using an older
version can expose you to security issues)
For solution #3, you would put this in your gemfile:
gem 'nokogiri', '1.4.7'
On Yosemite 10.10 the following steps solved my issues completely:
sudo xcode-select -switch /Library/Developer/CommandLineTools
gem uninstall nokogiri libxml-ruby
gem install nokogiri
This thread on GitHub gave me the trick I needed get Nokogiri 1.6.2 to install:
My ~/.gitconfig had the setting autocrlf = input. When I remove this setting the nokogiri build succeeds.
On Yosemite 10.10 this workaround worked for me:
gem install nokogiri -- --use-system-libraries
For #CentOS I needed to do the following:
gem update --system
yum install libxml2-devel libxslt-devel ruby-devel
gem install nokogiri -- --use-system-libraries
This is an old thread, but I hit similar issues, and the solution in my case was quite different to those posted so far.
After some digging, I found this thread:
https://github.com/bundler/bundler/issues/2648#issuecomment-25124800
It talks about bundler using a different version of ruby to that used by gem.
From OP's paste, we can see bundler is using the Mac system copy of ruby:
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
In my case I found that gem was coming from brew; which gem gave /usr/local/bin/gem which symlinks to /Cellar/ruby/2.3.3/bin/gem. My guess is that the OP's case was the same.
So, gem and bundler are not working off the same ruby installation, which explains why the OP sees this:
When I run gem list, I have nokogiri (1.6.2.1), but when running bundle install it displays the error.
In my case, I simply ran gem install bundler, which made bundler start using the brew version of ruby, and all problems disappeared.
On OSX 10.12 (Sierra) this worked for me:
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2
I had this exact issue. I run a rails environment on a mac. After I upgraded from Yosemite to Sierra I believe thats when it started.
To fix the problem I just had to install xcode command line tools. I don't know if the Sierra upgrade removed them or what.
xcode-select --install
(this will install the xcode command line tools)
Also another symptom..things like git status won't work. After this i was able to do rails new appname and it was fine.
This can be fixed by installing libxml2:
brew install libxml2
bundle config build.nokogiri --use-system-libraries
bundle install
This is a problem with macOS, I tried everything above but nothing was working, So tried to install versions of libxml2 but everything in vain.
So use the below command to you will be in good shape then,
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Resources