Nokogiri install on a Redhat VM fails - ruby-on-rails

I'm trying to setup a new Redhat VM that will run my Redhat Ruby on Rails application.
I am trying to bundle install and it's not working. It keeps telling me to install Nokogiri, but I do install it but I still get the error.
Here is how I installed Nokogiri
$ sudo gem install nokogiri -v 1.5.11
Building native extensions. This could take a while...
Successfully installed nokogiri-1.5.11
1 gem installed
Then, in my Rails app I do bundle install and I get this error:
Installing nokogiri (1.5.11)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/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
--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/gsidevas/.rvm/rubies/ruby-1.9.3-p448/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
/home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
from /home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:970:in `block in find_header'
from /home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
from /home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
from /home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
from /home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
from /home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
from /home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/mkmf.rb:969:in `find_header'
from extconf.rb:116:in `<main>'
Gem files will remain installed in /home/gsidevas/.rvm/gems/ruby-1.9.3-p448/gems/nokogiri-1.5.11 for inspection.
Results logged to /home/gsidevas/.rvm/gems/ruby-1.9.3-p448/gems/nokogiri-1.5.11/ext/nokogiri/gem_make.out
An error occurred while installing nokogiri (1.5.11), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.5.11'` succeeds before bundling.
Thoughts?

Following the guide here: http://nokogiri.org/tutorials/installing_nokogiri.html worked for my install using Homebrew 0.9 below are what they recommend for Red Hat.
Red Hat / CentOS
The easiest way to get Nokogiri installed on CentOS and RHEL seems to be the EPEL repository which contains a prebuilt nokogiri package. To use it, install the appropriate epel-release package for your OS, then run:
sudo yum install -y rubygem-nokogiri
To install using gem install is somewhat more complicated because of the age of the packages available from the central repositories. If you have rubygems installed, you may be able to install nokogiri via gem install. If you run intro problems, try installing these packages as well.
sudo yum install -y gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel
CentOS 5 (and RHEL5) come installed with libxml 2.6.26 which, while not as offensively out-of-date as Mac Leopard, is still pretty damn old (released June 2006) and has known issues.
If you’re affected by any known bugs or are seeing odd behavior, you may want to consider uninstalling the RPMs for libxml2 and libxslt, and building them from source.
sudo yum remove -y libxml2-devel libxslt-devel
download the most recent libxml2 and libxslt from ftp://xmlsoft.org/libxml2/
./configure ; make ; sudo make install
Then install nokogiri specifying the libxml2 and libxslt install directories:
sudo gem install nokogiri -- --with-xml2-lib=/usr/local/lib
--with-xml2-include=/usr/local/include/libxml2
--with-xslt-lib=/usr/local/lib
--with-xslt-include=/usr/local/include
(Note that, by default, libxslt header files are installed into the root include directory, but libxml2 header files are installed into a subdirectory thereof named libxml2.)
Or, you know, whatever directories into which you installed libxml and libxslt. Good luck.

Here is how I installed nokogiri
$ sudo gem install nokogiri -v 1.5.11
...
/home/gsidevas/.rvm/rubies/ruby-1.9.3-p448/bin/ruby extconf.rb
You used sudo to install Nokogiri when you're using a personal RVM sandbox. Don't do that. The RVM directions for installing gems specifically says:
DO NOT use sudo...
to work with RVM gems. When you do sudo you are running commands as root, another user in another shell and hence all of the setup that RVM has done for you is ignored while the command runs under sudo (such things as GEM_HOME, etc...). So to reiterate, as soon as you 'sudo' you are running as the root system user which will clear out your environment as well as any files it creates are not able to be modified by your user and will result in strange things happening. (You will start to think that someone has a voodoo doll of your application...)
Next:
checking for libxml/parser.h... *** extconf.rb failed ***
Looks like you're missing the devel package for libxml.

try accessing the mkmf.log file and see what information is listed in there. I had a similar issue on Mac OS and I remember having to delete a file because it was corrupted.

Struggled for hours with this error, finally what I needed was:
yum install cmake
cheers

On CentOS the missing compiler environment was the cause for my gem problem:
yum install gcc
yum install cmake
yum install ruby-devel

Related

Cant install rails

I have a new set up, and I keep getting an error when I am trying to install rails. I have used RVM to use ruby 2.2.2, and I have checked through the config files.
I have followed various tutorials. I have uninstalled gcc ( though i may reinstall xcode )
and I have gone through various tutorials on how to install this
gem install rails [9:00:49]
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/Users/rrobin008c/.rvm/rubies/ruby-2.2.2/bin/ruby -r ./siteconf20150812-28205-1wdgrip.rb extconf.rb
checking if the C compiler accepts -O2 -arch x86_64... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... yes
checking for iconv... yes
************************************************************************
IMPORTANT NOTICE:
Building Nokogiri with a packaged version of libxml2-2.9.2
with the following patches applied:
- 0001-Revert-Missing-initialization-for-the-catalog-module.patch
- 0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch
Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:
gem install nokogiri -- --use-system-libraries
[--with-xml2-config=/path/to/xml2-config]
[--with-xslt-config=/path/to/xslt-config]
If you are using Bundler, tell it to use the option:
bundle config build.nokogiri --use-system-libraries
bundle install
Note, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
************************************************************************
Extracting libxml2-2.9.2.tar.gz into tmp/x86_64-apple-darwin14.4.0/ports/libxml2/2.9.2... OK
Running patch with /Users/rrobin008c/.rvm/gems/ruby-2.2.2/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... OK
Running patch with /Users/rrobin008c/.rvm/gems/ruby-2.2.2/gems/nokogiri-1.6.6.2/ports/patches/libxml2/0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch...
Running 'patch' for libxml2 2.9.2... OK
Running 'configure' for libxml2 2.9.2... ERROR, review '/Users/rrobin008c/.rvm/gems/ruby-2.2.2/gems/nokogiri-1.6.6.2/ext/nokogiri/tmp/x86_64-apple-darwin14.4.0/ports/libxml2/2.9.2/configure.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=/Users/rrobin008c/.rvm/rubies/ruby-2.2.2/bin/$(RUBY_BASE_NAME)
--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
/Users/rrobin008c/.rvm/gems/ruby-2.2.2/gems/mini_portile-0.6.2/lib/mini_portile.rb:279:in `block in execute': Failed to complete configure task (RuntimeError)
from /Users/rrobin008c/.rvm/gems/ruby-2.2.2/gems/mini_portile-0.6.2/lib/mini_portile.rb:271:in `chdir'
from /Users/rrobin008c/.rvm/gems/ruby-2.2.2/gems/mini_portile-0.6.2/lib/mini_portile.rb:271:in `execute'
from /Users/rrobin008c/.rvm/gems/ruby-2.2.2/gems/mini_portile-0.6.2/lib/mini_portile.rb:66:in `configure'
from /Users/rrobin008c/.rvm/gems/ruby-2.2.2/gems/mini_portile-0.6.2/lib/mini_portile.rb:109:in `cook'
from extconf.rb:278:in `block in process_recipe'
from extconf.rb:177:in `tap'
from extconf.rb:177:in `process_recipe'
from extconf.rb:475:in `<main>'
extconf failed, exit code 1
Gem files will remain installed in /Users/rrobin008c/.rvm/gems/ruby-2.2.2/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /Users/rrobin008c/.rvm/gems/ruby-2.2.2/extensions/x86_64-darwin-14/2.2.0-static/nokogiri-1.6.6.2/gem_make.out
Manually install nokogiri
gem install nokogiri -v VERSION_YOU_WANT -- --use-system-libraries
Check out "nokogiri gem installation error".
Before you run bundle install, run:
bundle config build.nokogiri --use-system-libraries
or
gem install nokogiri -- --use-system-libraries
After that you can run:
bundle install
For other bugs read the Nokogiri install documentation.
I went through the various tutorials and my output looked like this:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/Users/rrobin008c/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20150812-2574-6ejap3.rb extconf.rb
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling breakpoint.c
make: /usr/bin/gcc-4.2: No such file or directory
make: *** [breakpoint.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/rrobin008c/.rvm/gems/ruby-2.2.1/gems/byebug-5.0.0 for inspection.
Results logged to /Users/rrobin008c/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-14/2.2.0-static/byebug-5.0.0/gem_make.out
An error occurred while installing byebug (5.0.0), and Bundler cannot continue.
Make sure that `gem install byebug -v '5.0.0'` succeeds before bundling.
The significant part is
make: /usr/bin/gcc-4.2: No such file or directory
After this I asked:
$which gcc
/usr/bin/gcc
Follow "OS X Mountain Lion: gcc-4.2 No such file or directory" and everything should work after that.
I would recommend running
brew doctor
rvm reinstall
rvm reinstall (ruby version here)
gem pristine all
sudo gem install rails
If you get to many error best thing to do is remove rails and ruby completely
first type this
tarun#tarun:~$ which ruby
/home/tarun/.rbenv/shims/ruby
tarun#tarun:~$ which rails
/home/tarun/.rbenv/shims/rails
then copy the path and use this command to remove the file
rm -rf /home/tarun/.rbenv/shims/ruby
rm -rf /home/tarun/.rbenv/shims/rails
and same way you can check which rbenv and which rvm and remove by using this same method.
And use
grep -rl rails
grep -rl ruby
this will show path of all files which have rails keyword.So that you can know that have you removed rails and ruby completely.
And follow steps given here to reinstall it
https://www.digitalocean.com/community/tutorials/how-to-install-ruby-on-rails-with-rbenv-on-ubuntu-14-04

Ruby: Compilation error during installation of ‘rails’ gem on macOS

When I install rails in macOS by running
$ sudo gem install rails
I got the following.
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20150702-37637-10z8fhh.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
checking for gzdopen() in -lz... yes
checking for iconv... yes
************************************************************************
IMPORTANT NOTICE:
Building Nokogiri with a packaged version of libxml2-2.9.2
with the following patches applied:
- 0001-Revert-Missing-initialization-for-the-catalog-module.patch
- 0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch
Team Nokogiri will keep on doing their best to provide security
updates in a timely manner, but if this is a concern for you and want
to use the system library instead; abort this installation process and
reinstall nokogiri as follows:
gem install nokogiri -- --use-system-libraries
[--with-xml2-config=/path/to/xml2-config]
[--with-xslt-config=/path/to/xslt-config]
If you are using Bundler, tell it to use the option:
bundle config build.nokogiri --use-system-libraries
bundle install
Note, however, that nokogiri is not fully compatible with arbitrary
versions of libxml2 provided by OS/package vendors.
************************************************************************
Extracting libxml2-2.9.2.tar.gz into tmp/x86_64-apple-darwin14/ports/libxml2/2.9.2... OK
Running patch with /Library/Ruby/Gems/2.0.0/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... OK
Running patch with /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2/ports/patches/libxml2/0002-Fix-missing-entities-after-CVE-2014-3660-fix.patch...
Running 'patch' for libxml2 2.9.2... OK
Running 'configure' for libxml2 2.9.2... OK
Running 'compile' for libxml2 2.9.2... ERROR, review '/Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2/ext/nokogiri/tmp/x86_64-apple-darwin14/ports/libxml2/2.9.2/compile.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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/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
/Library/Ruby/Gems/2.0.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:279:in `block in execute': Failed to complete compile task (RuntimeError)
from /Library/Ruby/Gems/2.0.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:271:in `chdir'
from /Library/Ruby/Gems/2.0.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:271:in `execute'
from /Library/Ruby/Gems/2.0.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:70:in `compile'
from /Library/Ruby/Gems/2.0.0/gems/mini_portile-0.6.2/lib/mini_portile.rb:110:in `cook'
from extconf.rb:278:in `block in process_recipe'
from extconf.rb:177:in `tap'
from extconf.rb:177:in `process_recipe'
from extconf.rb:475:in `<main>'
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/nokogiri-1.6.6.2/gem_make.out
Building gems with native extensions is always a pain. You need to have several libs or compile tools installed. In case of nokogiri it's libxml. For this reason i would recommend to use rvm for getting started. RVM is not the cleanest tool, when it comes to unix philosophy, but it's a full-stack solution, meaning that it just works out of the box. It will install all the dependencies for you, using the default osx package manager. As a package manager i recommend homebrew.
#install homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
#install rvm into $HOME
brew install gpg
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash -s stable
rvm install ruby --latest
gem install rails #no sudo, as ruby is in $HOME

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

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 /

rvm install 1.9.3 leading to ImageMagick installation issue

I was using Ruby 1.9.2 for my RoR 3.2.11 project
All worked fine until I had to upgrade to Ruby 1.9.3 because a gem required it.
By the same occasion I tried to make good use of RVM.
Installed ruby 1.9.3
rvm install 1.9.3 -C --with-openssl-dir=$HOME/.rvm/usr
Created .rvmrc
cd ./my_project/
rvm --create --rvmrc 1.9.3#project
Cleaned up my global gemset
rvm gemset empty
cd into my project and run installed gems
bundle
Error log
Installing rmagick (2.13.2)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/joel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for /opt/local/bin/gcc-apple-4.2... yes
checking for Magick-config... yes
Warning: Found more than one ImageMagick installation. This could cause problems at runtime.
/usr/local/ImageMagick/bin/Magick-config reports version 6.7.3 Q16 is installed in
/usr/local/bin/Magick-config reports version 6.7.1 Q16 is installed in /usr/local/Cellar/imagemagick/6.7.1-1
Using 6.7.3 Q16 from .
checking for ImageMagick version >= 6.4.9... yes
checking for HDRI disabled version of ImageMagick... yes
checking for stdint.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/joel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby
/Users/joel/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/joel/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
from /Users/joel/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:931:in `block in have_header'
from /Users/joel/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
from /Users/joel/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
from /Users/joel/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/joel/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
from /Users/joel/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/joel/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
from /Users/joel/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
from /Users/joel/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/mkmf.rb:930:in `have_header'
from extconf.rb:194:in `<main>'
Gem files will remain installed in /Users/joel/.rvm/gems/ruby-1.9.3-p429#creativebank/gems/rmagick-2.13.2 for inspection.
Results logged to /Users/joel/.rvm/gems/ruby-1.9.3-p429#my_project/gems/rmagick-2.13.2/ext/RMagick/gem_make.out
An error occurred while installing rmagick (2.13.2), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.13.2'` succeeds before bundling.
At first sight, it looks like I have 2 installations of ImageMagick and that I could spare one.
So my first question would be how to uninstall clean ImageMagick version 6.7.1 Q16?
and of course if there is something else I could try to solve this issue.
ADDITIONAL INFO about packages installed
I know that MacPort and Brew don't work well together but I always been worried about removing MacPort in its entirety. Could that be the problem?
port list | grep magick
p5-perlmagick #6.8.6-0 perl/p5-perlmagick
p5.8-perlmagick #6.8.6-0 perl/p5-perlmagick
p5.10-perlmagick #6.8.6-0 perl/p5-perlmagick
p5.12-perlmagick #6.8.6-0 perl/p5-perlmagick
p5.14-perlmagick #6.8.6-0 perl/p5-perlmagick
p5.16-perlmagick #6.8.6-0 perl/p5-perlmagick
php-gmagick #1.1.2RC1 php/php-gmagick
php53-gmagick #1.1.2RC1 php/php-gmagick
php54-gmagick #1.1.2RC1 php/php-gmagick
php55-gmagick #1.1.2RC1 php/php-gmagick
php-imagick #3.1.0RC2 php/php-imagick
php53-imagick #3.1.0RC2 php/php-imagick
php54-imagick #3.1.0RC2 php/php-imagick
php55-imagick #3.1.0RC2 php/php-imagick
php-magickwand #1.0.9-2 php/php-magickwand
php53-magickwand #1.0.9-2 php/php-magickwand
php54-magickwand #1.0.9-2 php/php-magickwand
php55-magickwand #1.0.9-2 php/php-magickwand
php5-gmagick #1.1.2RC1 php/php5-gmagick
php5-imagick #3.0.1 php/php5-imagick
php5-magickwand #1.0.9-2 php/php5-magickwand
rb-rmagick #2.13.2 ruby/rb-rmagick
brew list
faac grc jasper lame libtiff libvpx pkg-config wget xvid
ffmpeg imagemagick jpeg libogg libvorbis little-cms theora x264 yasm
UPDATE
Remove MacPorts
sudo port -f uninstall installed
Uninstalled brew ImageMagick and installed it again with brew
Installed XCode latest version
and ran bundle, I do get a different message, C compiler missing ... argh, what should I do next, I am trying installing gcc with brew, but not sure that I am heading the right direction, please help:
Installing rmagick (2.13.2)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/joel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for /opt/local/bin/gcc-apple-4.2... no
No C compiler found in ${ENV['PATH']}. See mkmf.log for details.
*** 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/joel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby
Gem files will remain installed in /Users/joel/.rvm/gems/ruby-1.9.3-p429#creativebank/gems/rmagick-2.13.2 for inspection.
Results logged to /Users/joel/.rvm/gems/ruby-1.9.3-p429#creativebank/gems/rmagick-2.13.2/ext/RMagick/gem_make.out
An error occurred while installing rmagick (2.13.2), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.13.2'` succeeds before bundling.
GCC 4.2
which gcc => /usr/bin/gcc
gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
echo $PATH
/bin;/usr/bin;/usr/sbin;/sbin;/usr/local/ImageMagick/bin:/usr/local/heroku/bin:/Applications/Postgres.app/Contents/MacOS/bin:/Users/joel/.rvm/gems/ruby-1.9.3-p429#biowatts/bin:/Users/joel/.rvm/gems/ruby-1.9.3-p429#global/bin:/Users/joel/.rvm/rubies/ruby-1.9.3-p429/bin:/Users/joel/.rvm/bin:/usr/bin;usr/local/ImageMagick/bin:/usr/local/heroku/bin:/Applications/Postgres.app/Contents/MacOS/bin:/usr/local/ImageMagick/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/joel
NEW ERROR MESSAGE:
Installing json (1.8.0)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/joel/.rvm/rubies/ruby-1.9.3-p429/bin/ruby extconf.rb
creating Makefile
make
compiling generator.c
make: /opt/local/bin/gcc-apple-4.2: No such file or directory
make: *** [generator.o] Error 1
Gem files will remain installed in /Users/joel/.rvm/gems/ruby-1.9.3-p429#biowatts/gems/json-1.8.0 for inspection.
Results logged to /Users/joel/.rvm/gems/ruby-1.9.3-p429#biowatts/gems/json-1.8.0/ext/json/ext/generator/gem_make.out
It obviously looking for /opt/local/bin/gcc-apple-4.2 which I deleted recklessly while following these instructions to move from Macportd to homebrew :(
NOW INSTALLING MISSING PACKAGES with homebrew
brew install apple-gcc42
brew install libxml2
Couple things:
Remove MacPorts (you may list all things you installed with them and reinstall those with brew)
Remove imagemagick from homebrew
Install imagemagick again with brew
You're getting this error You have to install development tools first. which (I guess) means you need to install XCode command line tools.
Then bundle install should work!
you need to reinstall your ruby after removing the package manager you used to install it, the easiest way is to:
rvm reinstall 1.9.3-p429
In combination to the 2 first answers
brew uninstall imagemagick
and used http://cactuslab.com/imagemagick/
Then in my .bash_profile I set
PKG_CONFIG_PATH=/opt/ImageMagick/lib/pkgconfig
C_INCLUDE_PATH=/opt/ImageMagick/include/ImageMagick-6
and finally
bundle

Resources