nokogiri 1.9.1 install failed on MacOS Catalina - ruby-on-rails

I am getting an error and bundle install fails:
An error occurred while installing nokogiri (1.9.1), and Bundler cannot continue. Make sure that gem install nokogiri -v '1.9.1' --source 'https://rubygems.org/' succeeds before bundling.
I have tried many commands from stack overflow but no luck yet.
After reading some posts about the issue I added the following environment variables but the bundle install still fails.
export PATH="/usr/local/opt/libxslt/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/libxslt/lib"
export CPPFLAGS="-I/usr/local/opt/libxslt/include"
sudo gem install nokogiri -v "1.9.1" -- --use-system-libraries
Building native extensions with: '--use-system-libraries'
This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/Users/wiii/.rbenv/versions/2.1.5/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... no
Building nokogiri using system libraries.
checking for xmlParseDoc() in libxml/parser.h... yes
checking for xsltParseStylesheetDoc() in libxslt/xslt.h... no
checking for xsltParseStylesheetDoc() in -lxslt... no
checking for xsltParseStylesheetDoc() in -llibxslt... no
-----
libxslt is missing. Please locate mkmf.log to investigate how it is failing.
-----
*** 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/wiii/.rbenv/versions/2.1.5/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
--with-xsltlib
--without-xsltlib
--with-libxsltlib
--without-libxsltlib
extconf failed, exit code 1
Debugging info are attached below:
$ which ruby
/Users/wiii/.rbenv/shims/ruby
$ which bundle
/Users/wiii/.rbenv/shims/bundle
$ which gem
/Users/wiii/.rbenv/shims/gem
$ ruby --version
ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin19.0]
$ bundle --version
Bundler version 1.17.3
$ gem --version
2.2.2
Homebrew
% brew list
ansible kind libxslt openssl#1.0 ruby-build
autoconf kubectx libyaml openssl#1.1 sqlite
gdbm kubernetes-cli mpdecimal pkg-config tcl-tk
go libgcrypt mysql#5.7 protobuf tomcat#8
htop libgpg-error ncurses python#3.9 xz
icu4c libiconv node rbenv
k9s libxml2 openjdk readline
intellij-idea
Could anyone share some thoughts on what might be causing the issues here?

Nokogiri is an open source software library to parse HTML and XML in Ruby. It depends on libxml2 and libxslt to provide its functionality. without it Rails is non-functional.
it seems as if your macOS is missing some essential libraries required for nokogiri to run on your computer.
you can go ahead and first uninstall nokogiri and any other interfering library that you might have installed during your endeavor to solve this issue
run brew uninstall nokogiri
upon uninstalling, you can run brew install libxml2 libxslt to install the most essential libraries using brew
after that, run gem install nokogiri --platform=ruby -- --use-system-libraries to successfully install nokogiri

Related

Windows 10 + Ruby 3.1.2 -- Cannot install nokogiri

I am quite new to development and just trying to set my Windows 10 PC up for Rails development. I found a tutorial that seemed quite clear and achievable here.
I was able to install Ruby 3.1.2 and unzipped it to a permanent folder. I added it to path, and then moved on to build tools. I downloaded MSYS2 from their site and installed, then set up pacman, then RubyInstaller2--installing the MSYS2 and MINGW development toolchain. I was down to installing the C-dependent gems and was able to install sqlite3 using:
ridk exec pacman -S mingw-w64-x86_64-sqlite3
gem install sqlite3 --platform ruby
And went on to install nokogiri gem:
ridk execpacman -S mingw-w64-x86_64-libxslt
gem install nokogiri --platform ruby -- --use-system-libraries
This final gem install line is where I have failed. I am very new at most of this and am close to trying to install WSL or a virtual machine, but I thought it was sensible to try and troubleshoot and find the solution.
C:\WINDOWS\system32>gem install nokogiri --platform ruby -- --use-system-libraries
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions with: '--use-system-libraries'
This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
current directory: C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/lib/ruby/gems/3.1.0/gems/nokogiri-1.13.6/ext/nokogiri
C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/bin/ruby.exe -I C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/lib/ruby/site_ruby/3.1.0 -r ./siteconf20220511-16300-lhgizk.rb extconf.rb --use-system-libraries
checking for whether -std=c99 is accepted as CFLAGS... yes
checking for whether -Wno-declaration-after-statement is accepted as CFLAGS... yes
checking for whether -g is accepted as CFLAGS... yes
checking for whether -Winline is accepted as CFLAGS... yes
checking for whether -Wmissing-noreturn is accepted as CFLAGS... yes
checking for whether "-Idummypath" is accepted as CPPFLAGS... yes
Building nokogiri using system libraries.
checking for gzdopen() in -lz... yes
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no
checking for libxml-2.0 using `pkg_config`... no
Please install either the `pkg-config` utility or the `pkg-config` rubygem.
checking for xmlParseDoc() in -lxml2... no
checking for xmlParseDoc() in -llibxml2... no
-----
extconf.rb:285:in `ensure_package_configuration'
extconf.rb:648:in `<main>'
xml2 is missing. Please locate mkmf.log to investigate how it is failing.
-----
*** 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:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/bin/$(RUBY_BASE_NAME)
--help
--clean
--prevent-strip
--enable-system-libraries
--disable-system-libraries
--use-system-libraries
--enable-system-libraries
--disable-system-libraries
--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-z-dir
--without-z-dir
--with-z-include
--without-z-include=${z-dir}/include
--with-z-lib
--without-z-lib=${z-dir}/lib
--with-zlib
--without-zlib
--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-xml2lib
--without-xml2lib
--with-libxml2-dir
--without-libxml2-dir
--with-libxml2-include
--without-libxml2-include=${libxml2-dir}/include
--with-libxml2-lib
--without-libxml2-lib=${libxml2-dir}/lib
--with-libxml2lib
--without-libxml2lib
--with-libxml-2.0-dir
--without-libxml-2.0-dir
--with-libxml-2.0-include
--without-libxml-2.0-include=${libxml-2.0-dir}/include
--with-libxml-2.0-lib
--without-libxml-2.0-lib=${libxml-2.0-dir}/lib
--with-libxml-2.0-config
--without-libxml-2.0-config
--with-pkg-config
--without-pkg-config
--with-xml2lib
--without-xml2lib
--with-libxml2lib
--without-libxml2lib
To see why this extension failed to compile, please check the mkmf.log which can be found here:
C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/nokogiri-1.13.6/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/lib/ruby/gems/3.1.0/gems/nokogiri-1.13.6 for inspection.
Results logged to C:/Dev/Dependencies/Ruby/rubyinstaller-3.1.2-1-x64/lib/ruby/gems/3.1.0/extensions/x64-mingw-ucrt/3.1.0/nokogiri-1.13.6/gem_make.out
C:\WINDOWS\system32>
So, when I read the bit about "please install the pkg-config rubygem, I looked up how to do it and tried to install in MSYS2, which it appeared to do.
windows is not really the best option with rails there will be a lot of issues and everything gets more complicated see this Limitations in running Ruby/Rails on windows
Linux is highly recommend
you can use dual-booting or WSL either is fine

Nokogiri gem build error failed to build gem native extension on WSL with RVM

Im using WSL (ubuntu) for windows 10 with RVM version 1.29.12.
Ruby version is 2.4.1p11. Bundler version 1.16.4.
When I execute bundle install, It stops on nokogiri and throws this error:
Fetching gem metadata from https://rubygems.org/............
Using rake 12.3.0
Using concurrent-ruby 1.0.5
Using i18n 0.9.1
Using minitest 5.10.3
Using thread_safe 0.3.6
Using tzinfo 1.2.4
Using activesupport 5.1.4
Using builder 3.2.3
Using erubi 1.7.0
Using mini_portile2 2.3.0
Fetching nokogiri 1.8.1
Installing nokogiri 1.8.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
checking if the C compiler accepts ... no
Building nokogiri using system libraries.
pkg-config could not be used to find libxml-2.0
Please install either `pkg-config` or the pkg-config gem per
gem install pkg-config -v "~> 1.1"
pkg-config could not be used to find libxslt
Please install either `pkg-config` or the pkg-config gem per
gem install pkg-config -v "~> 1.1"
pkg-config could not be used to find libexslt
Please install either `pkg-config` or the pkg-config gem per
gem install pkg-config -v "~> 1.1"
ERROR: cannot discover where libxml2 is located on your system. please make sure `pkg-config` is installed.
*** 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/mike/.rvm/rubies/ruby-2.4.1/bin/$(RUBY_BASE_NAME)
--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
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/mnt/c/Users/test/vendor/bundle/ruby/2.4.0/extensions/x86_64-linux/2.4.0/nokogiri-1.8.1/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /mnt/c/Users/test/vendor/bundle/ruby/2.4.0/gems/nokogiri-1.8.1 for inspection.
Results logged to /mnt/c/Users/test/vendor/bundle/ruby/2.4.0/extensions/x86_64-linux/2.4.0/nokogiri-1.8.1/gem_make.out
An error occurred while installing nokogiri (1.8.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.8.1' --source 'https://rubygems.org/'` succeeds before bundling.
In Gemfile:
view_source_map was resolved to 0.1.4, which depends on
rails was resolved to 5.1.4, which depends on
actioncable was resolved to 5.1.4, which depends on
actionpack was resolved to 5.1.4, which depends on
actionview was resolved to 5.1.4, which depends on
rails-dom-testing was resolved to 2.0.3, which depends on
nokogiri
I have tried several suggestions I found online like doing
gem install pkg-config -v "~> 1.1"
or
sudo apt-get install libxml2-dev libxslt-dev
but I can't seem to get rid of the error.
I also tried installing the nokogiri separately and then executed bundle install again but the same issue still occurs.
Thanks in advance.
Try this. This is instructing bundler to look for libraries
bundle config build.nokogiri --use-system-libraries
bundle install
If above doesn't work. check your log files. In most scenarios some libraries are missed.
sudo apt-get install zlib1g-dev
sudo apt-get install libxml2-dev
sudo apt-get install libxslt-dev

Problems installing Nokogiri -v 1.6.1 and libxml2

I'm running Mac OSX "Yosemite", and I've been trying to install Nokogiri 1.6.1, but I keep running into the error below.
This is the error I ran into when I was trying to install Nokogiri 1.6.1:
sh-3.2# gem install nokogiri -v 1.6.1
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20150819-49747-fafnk9.rb extconf.rb
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-apple-darwin14.4.0/ports/libxml2/2.8.0... OK
Running 'configure' for libxml2 2.8.0... OK
Running 'compile' for libxml2 2.8.0... OK
Running 'install' for libxml2 2.8.0... OK
Activating libxml2 2.8.0 (from /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin14.4.0/libxml2/2.8.0)...
Extracting libxslt-1.1.26.tar.gz into tmp/x86_64-apple-darwin14.4.0/ports/libxslt/1.1.26... OK
Running 'configure' for libxslt 1.1.26... OK
Running 'compile' for libxslt 1.1.26... OK
Running 'install' for libxslt 1.1.26... OK
Activating libxslt 1.1.26 (from /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin14.4.0/libxslt/1.1.26)...
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... yes
checking for xmlParseDoc() in -lxml2... no
-----
libxml2 is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** 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
--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
--with-iconvlib
--without-iconvlib
--with-xml2lib
--without-xml2lib
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/nokogiri-1.6.1/gem_make.out
I tried everything on http://www.nokogiri.org/tutorials/installing_nokogiri.html, but I have been unsuccessful. I tried to install libxml2 to install Nokogiri 1.6.1, but my terminal says:
Cowardly refusing to `sudo brew install`
Sometimes installing Nokogiri is tricky as it has several dependencies, which is what happened in your case too.
"Installing Nokogiri" is a step-by-step tutorial on how to install Nokogiri on your Mac OSX system.
You need to install Package first
xcode-select --install
then
gem install nokogiri

An error occured with Nokogiri while bundle install (OSx Mavericks)

i'm new in rails and i don't understand why Nokogiri don't want to install while i try to bundle install :
barnab21:sample_app barnab21$ sudo bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as
root will break this application for all non-root users on this machine.
Fetching gem metadata from http://rubygems.org/.........
Using rake 0.9.6
Using abstract 1.0.0
Using activesupport 3.0.7
Using builder 2.1.2
Using i18n 0.5.4
Using activemodel 3.0.7
Using erubis 2.6.6
Using rack 1.2.8
Using rack-mount 0.6.14
Using rack-test 0.5.7
Using tzinfo 0.3.39
Using actionpack 3.0.7
Using mime-types 1.25.1
Using polyglot 0.3.5
Using treetop 1.4.15
Using mail 2.2.20
Using actionmailer 3.0.7
Using arel 2.0.10
Using activerecord 3.0.7
Using activeresource 3.0.7
Using diff-lcs 1.1.3
Using mini_portile 0.6.0
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 /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.2.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-13/2.0.0/nokogiri-1.6.2.1/gem_make.out
An error occurred while installing nokogiri (1.6.2.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.2.1'` succeeds before bundling.
I try this :
$ xcode-select --install
then gem install nogoriki, but that doesn't work.
I try this, from a other stackoverflow thread :
If previously installed, uninstall the gem:
$ gem uninstall nokogiri
Use Homebrew to install libxml2, libxslt and libiconv if needed:
$ brew install libxml2 libxslt libiconv
Install the gem specifying the paths to the libraries to be linked against:
$ NOKOGIRI_USE_SYSTEM_LIBRARIES=1 gem install nokogiri -- --use-system-libraries --with-iconv-dir="$(brew --prefix libiconv)" --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config" --with-xslt-config="$(brew --prefix libxslt)/bin/xslt-config"
And :
This could take a while...
Building nokogiri using system libraries.
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --use-system-libraries --with-iconv-dir=/usr/local/opt/libiconv --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xslt-config=/usr/local/opt/libxslt/bin/xslt-config
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.
I Don't know what to try... thx
My mac : Macbook pro retina 15 , mavericks
After $ brew install libxml2 libxslt libiconv I used
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.7.8/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.7.8/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib
and it works for me. You can try it, but change versions of libraries to yours.
So I'm on Yosemite, thought this might help.
The solutions above didn't work for me, but then I realized a couple of the directories had somehow gotten moved into themselves
--with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2/libxml
--with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib/lib
So it might be worth checking all the directories, if anyone still has the problem (ha I don't think I put the files like that, but it's totally possible)
The full command I used:
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-xslt-dir=/usr/local/Cellar/libxslt/1.1.28 --with-iconv-include=/usr/local/Cellar/libiconv/1.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib/lib
got same problem in Redhat linux 6
you need to install packages libxml2 & libxml2-devel and libxslt & libxslt-devel.
{you need to install libgcrypt & libgcrpt-devel as it is required to install above packages }
make sure you install latest versions.
if package already exist then you need to upgrade those packages.
just use
rpm -uvh --replacefiles {your_packagename.rpm}
hope it helps. comment if you need more help.

An error occurred while installing nokogiri (1.5.2)

When I try to run a ruby on rails project I got an error:
An error occurred while installing nokogiri (1.5.2), and bundle cannot continue.
Make sure that 'gem install nokogiri -v 1.5.2 succeed before building.
I'm working on Ubuntu 10.10
My co-worker uses on Windows/RVM and does not have this problem.
Edit:
gem_make.out
/opt/bitnami/ruby/bin/ruby extconf.rb
extconf.rb:10: Use RbConfig instead of obsolete and deprecated Config.
checking for libxml/parser.h... yes
checking for libxslt/xslt.h... yes
checking for libexslt/exslt.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
-----
libiconv is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** 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/bitnami/ruby/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-iconvlib
--without-iconvlib
From the output:
libiconv is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
Install libiconv.
nokogiri requirements
sudo apt-get install libxslt-dev libxml2-dev
sudo gem install nokogiri
You can visit http://nokogiri.org/tutorials/installing_nokogiri.html
It should not be necessary to install any additonal package. You can use the libraries includes with BitNami (in /opt/bitnami/common). You just need to load the BitNami environment and specify the path to libxml2 files. While testing this I got similar issue but with libxml2, a similar solution can be applied for the iconv error that you are receiving.
$/opt/bitnami/rubyconsole
$sudo gem install nokogiri -- --with-xml2-dir=/opt/bitnami/common --with-xml2-include=/opt/bitnami/common/include/libxml2
Building native extensions. This could take a while...
Successfully installed nokogiri-1.5.2
1 gem installed
Installing ri documentation for nokogiri-1.5.2...
Installing RDoc documentation for nokogiri-1.5.2...
The solution of installing the system packages and used them should also work.
what works for me (Mac OS X):
$ xcode-select --install

Resources