libxml-ruby: Failed to build gem native extension - macos

I'm trying to install libxml-ruby.
I have installed libxml2, libxslt and coreutils
I have also read other posts regarding the issue but none solved it for me.
brew list libxslt
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/bin/xslt-config
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/bin/xsltproc
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/include/libexslt/ (3 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/include/libxslt/ (21 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/libexslt.0.dylib
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/libxslt.1.dylib
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/pkgconfig/ (2 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/lib/ (5 other files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/share/aclocal/libxslt.m4
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/share/doc/ (90 files)
/opt/boxen/homebrew/Cellar/libxslt/1.1.28_1/share/man/ (3 files)
brew list libxml2
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/bin/xml2-config
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/bin/xmlcatalog
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/bin/xmllint
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/include/libxml2/ (47 files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/libxml2.2.dylib
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/cmake/libxml2/libxml2-config.cmake
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/pkgconfig/libxml-2.0.pc
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/lib/ (3 other files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/aclocal/libxml.m4
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/doc/ (153 files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/gtk-doc/ (55 files)
/opt/boxen/homebrew/Cellar/libxml2/2.9.4/share/man/ (4 files)
gem install libxml-ruby produces the following error:
Building native extensions. This could take a while...
ERROR: Error installing libxml-ruby:
ERROR: Failed to build gem native extension.
current directory: /opt/rubies/2.3.0/lib/ruby/gems/2.3.0/gems/libxml-ruby-2.9.0/ext/libxml
/opt/boxen/rbenv/versions/2.3.0/bin/ruby -r ./siteconf20160630-68248-1qaz7dk.rb extconf.rb
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
*** 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/boxen/rbenv/versions/2.3.0/bin/$(RUBY_BASE_NAME)
--with-xml2-config
--without-xml2-config
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
extconf failure: need libxml2.
Install the library or try one of the following options to extconf.rb:
--with-xml2-config=/path/to/xml2-config
--with-xml2-dir=/path/to/libxml2
--with-xml2-lib=/path/to/libxml2/lib
--with-xml2-include=/path/to/libxml2/include
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/opt/boxen/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-14/2.3.0-static/libxml-ruby-2.9.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /opt/boxen/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/libxml-ruby-2.9.0 for inspection.
Results logged to /opt/boxen/rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-14/2.3.0-static/libxml-ruby-2.9.0/gem_make.out

I had a similar issue after I had used brew to install libxml2
Brew link solved the issue brew link --force libxml2

Life after upgrading to macOS Mojave.
xcode-select --install
brew install libxml2
brew link --force libxml2
gem install libxml-ruby -v '2.9.0' -- --use-system-libraries=true --with-xml2-include="$(xcrun --show-sdk-path)"/usr/include/libxml2
In my example I installed version 2.9.0 of the libxml-ruby gem. Change the version string to suit your needs. If available, examine the Gemfile.lock to identify which version of libxml-ruby Bundler is needs to install.

Homebrew:
libxml2 is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
So, we need to set libxml path directly
brew install libxml2
gem install libxml-ruby \
-- \
--with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config"
P.S.
If you get the exception on lastest rubies:
Just ignore it. The gem was successfully installed. Just the Rdoc documentation generation failed.
The internal error was:
(NoMethodError) undefined method `[]' for nil:NilClass
ERROR: While executing gem ... (NoMethodError)
undefined method `[]' for nil:NilClass

macOS comes with libmxl2 installed, always, there is no need to use a utility like brew to install it first. Yet the headers are not found in /usr/include/libxml but in /usr/include/libxml2/libxml.
The configure script of the libxml-ruby gem tries to detect if libxml is installed by compiling code that looks like this:
#include <libxml/xmlversion.h>
But when compiling with the compiler shipped with Xcode, only this code would work:
#include <libxml2/libxml/xmlversion.h>
The trick is to let the configure script know where to find the headers. On a macOS system with Xcode installed, the following will work:
gem install libxml-ruby -v '3.1.0' -- --with-xml2-include=`xcrun --show-sdk-path`/usr/include/libxml2

The high level issue is shown here:
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
Basically, the installer is telling you it can't find libxml/xmlversion.h but more generally it most likely can't find your libxml2 location. It tells you which four directories it's looking in so the first step is to check those directories to see if libxml2 is there.
Assuming it's not in any of those four locations, you need to find it. Run find / -name xmlversion.h (might need sudo) to figure out where libxml2 got installed. Based on this answer I'm guessing your issue is that brew installed it to /usr/local/Cellar/libxml2 but you should confirm that. Once you have the location you can manually point your gem install command to it. Something like this: (but fill in path/to with your actual path)
gem install libxml-ruby --with-xml2-dir=/path/to/libxml2 --with-xml2-lib=/path/to/libxml2/lib --with-xml2-include=/path/to/libxml2/include

I also used brew to install libxml2 but needed the following options:
brew install libxml2 --with-xml2-config
gem install libxml-ruby -- --with-xml2-config=/usr/local/homebrew/opt/libxml2/bin/xml2-config

One solution is to:
cd /Library/Developer/CommandLineTools/Packages/ $
open macOS_SDK_headers_for_macOS_10.14.pkg
To force the reinstallation of the headers for macOS 10.14.

Related

Bundle install fails to install libxml-ruby

I'm a new to Ruby world and I need to clone an existing project.
The instructions are:
source .env.development
bundle install
But it fails with:
Using libv8 3.16.14.15
Fetching libxml-ruby 2.9.0
Installing libxml-ruby 2.9.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /Users/vlad/.rvm/gems/ruby-2.3.1/gems/libxml-ruby-2.9.0/ext/libxml
/Users/vlad/.rvm/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20181109-46682-fvgifh.rb extconf.rb --use-system-libraries
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... no
*** 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/vlad/.rvm/rubies/ruby-2.3.1/bin/$(RUBY_BASE_NAME)
--with-xml2-config
--without-xml2-config
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
extconf failure: need libxml2.
Install the library or try one of the following options to extconf.rb:
--with-xml2-config=/path/to/xml2-config
--with-xml2-dir=/path/to/libxml2
--with-xml2-lib=/path/to/libxml2/lib
--with-xml2-include=/path/to/libxml2/include
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/vlad/.rvm/gems/ruby-2.3.1/extensions/x86_64-darwin-18/2.3.0/libxml-ruby-2.9.0/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Users/vlad/.rvm/gems/ruby-2.3.1/gems/libxml-ruby-2.9.0 for inspection.
Results logged to /Users/vlad/.rvm/gems/ruby-2.3.1/extensions/x86_64-darwin-18/2.3.0/libxml-ruby-2.9.0/gem_make.out
An error occurred while installing libxml-ruby (2.9.0), and Bundler cannot continue.
Make sure that `gem install libxml-ruby -v '2.9.0'` succeeds before bundling.
In Gemfile:
upnxt_community_lib_common was resolved to 1.7.49, which depends on
upnxt_processing_lib_document was resolved to 2.0.0, which depends on
libxml-
If I want to execute the command that is suggested "gem install libxml-ruby -v '2.9.0'" I get the same error.
Operating System: MacOS Mojave, version 10.14.
Ruby version needed for the project: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin18]
I also tried this but it didn't helped.
Thanks in advance for any help!
These steps worked for me (source)
brew install libxml2
bundle config --global build.libxml-ruby --with-xml2-config="$(brew --prefix libxml2)/bin/xml2-config"
then bundle install worked as expected
I manage to fix this with the help of a colleague, if anybody else encounter this problem:
gem install libxml-ruby -v '2.9.0' -- --use-system-libraries --with-xml2-dir=/usr/local/Cellar/libxml2/2.9.8/include/libxml2/libxml/ --with-xml2-config=/usr/bin/xml2-config
Replace '2.9.0' with the libxml version that you need!
It solved for me in mac by running
gem install libxml-ruby -v '3.0.0' -- --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xml2-include=/usr/local/opt/libxml2/include
Just happened today.
$ brew link --force libxml2
Warning: Refusing to link macOS-provided software: libxml2
...
At first, I wasn't aware that there's a warning and it doesn't work anymore.
Then found this workaround and it worked for me.
bundle config build.libxml-ruby --use-system-libraries=true --with-xml2-include=/usr/local/opt/libxml2/include/libxml2/
I've encountered many tips while googling around today. I've tried to compile them into a logical order of some things to try:
Installing/debugging libxml on mac for ruby/rails.
There's a lot on this page already. But just to point out a few extra things I've gathered from elsewhere.
To me it seems more sensible to try to get a working bundle config command than to bypass this with a gem install command. So use skplunkerin's answer, or...
The following will configure it to use the system libxml headers:
bundle config --global build.libxml-ruby --with-xml2-include=`xcrun --show-sdk-path`/usr/include/libxml2
bundle install
...which worked better for me today. The libxml-ruby gem build was having issues with the latest homebrew installed libxml vs an older system libxml.

Install Nokogiri 1.6.1 under Ruby 2.0.0p353 (rvm based installation) fails (OSX Mavericks)?

I've tried to install Nokogiri 1.6.1 under Ruby and RVM but is failing with the following error:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/lmo0/.rvm/rubies/ruby-2.0.0-p353/bin/ruby extconf.rb
Extracting libxml2-2.8.0.tar.gz into tmp/x86_64-apple-darwin13.0.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 /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/nokogiri-1.6.1/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0)...
Extracting libxslt-1.1.26.tar.gz into tmp/x86_64-apple-darwin13.0.0/ports/libxslt/1.1.26... OK
Running 'configure' for libxslt 1.1.26... ERROR, review 'tmp/x86_64-apple-darwin13.0.0/ports/libxslt/1.1.26/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
--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/lmo0/.rvm/rubies/ruby-2.0.0-p353/bin/ruby
/Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/mini_portile-0.5.2/lib/mini_portile.rb:265:in `block in execute': Failed to complete configure task (RuntimeError)
from /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/mini_portile-0.5.2/lib/mini_portile.rb:257:in `chdir'
from /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/mini_portile-0.5.2/lib/mini_portile.rb:257:in `execute'
from /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/mini_portile-0.5.2/lib/mini_portile.rb:65:in `configure'
from /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/mini_portile-0.5.2/lib/mini_portile.rb:108:in `cook'
from extconf.rb:101:in `block in <main>'
from extconf.rb:131:in `call'
from extconf.rb:131:in `block in <main>'
from extconf.rb:122:in `tap'
from extconf.rb:122:in `<main>'
Gem files will remain installed in /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/nokogiri-1.6.1 for inspection.
Results logged to /Users/lmo0/.rvm/gems/ruby-2.0.0-p353/gems/nokogiri-1.6.1/ext/nokogiri/gem_make.out
Check your grep version and install latest via brew:
$ grep --version
grep (BSD grep) 2.5.1-FreeBSD
$ brew install grep --default-names
# If above fails, you probably need to tap
$ brew tap homebrew/dupes
$ brew install grep --default-names
$ grep --version
grep (GNU grep) 2.14.56-1e3d
From (this nokogiri issue)[https://github.com/sparklemotion/nokogiri/issues/935]:
"recent versions of OSX come with BSD grep, while older ones came with GNU grep. And that, your build script, perhaps requires GNU grep"
Stolen from Maverick's comment and duplicated here as an answer and not a comment because I've now run into this issue several times and would love to save someone else the headache. =X
You can try the solution which I used so far to fix the same...
Remove all older libxml-ruby and nokogiri
use below command for the same
sudo gem uninstall nokogiri libxml-ruby
then you can try out the version of nokogiri, was having issue. THat should works perfect.
sudo gem install nokogiri -v '1.6.1'
Much similar answer reported by Dan but some little bit change. Thanks.
I wrote a post on this after dealing with it myself. No need for homebrew.
There was a few issues I ran into, the first one being that the development tools cannot be found, and the second one that the libxml is too old.
Run the following commands in the rubyconsole:
$ sudo xcode-select -switch /Library/Developer/CommandLineTools
$ gem uninstall nokogiri libxml-ruby
$ gem install nokogiri
Turned out there is a bit simpler solution:
Remove this line in your ~/.bashrc or ~/.bash_profile file:
GREP_OPTIONS="--color=always"
with this one:
export GREP_OPTIONS="--color=auto"
This way you won't need to install any duplicates.
Thanks to MrPowers # Nokogiri Issues.
manually ./configure 'include' and 'lib' locations helped me out. libxml2 source layout is a bit strange, so i ended up with alike options:
gem install nokogiri -- --use-system-libraries --with-xslt-dir=/usr/local/opt/libxslt --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib
of course, version numbers depend upon what is actually installed. at the time of this writing there version were in the brew.
in my case /usr/local/Cellar/libxml2/2.9.1/include/libxml2 contains a single directory named libxml and /usr/local/Cellar/libxml2/2.9.1/lib contains libxml2.2.dylib libxml2.a libxml2.dylib pkgconfig xml2Conf.sh: these are what the script is looking for, no other combination made it compile using system libraries.
using homebrew nokogiri can be installed with neither outdated nor incompatible (recent) libxml2 and libxslt libraries as pointed out in this gist. working fine and fast for me.

Error installing debugger-linecache in Ruby 1.9.3

I need version 1.0.1 of debugger-linecache for a project, and I am facing the following error when trying to install.
trunk ☺ gem install debugger-linecache -v '1.0.1'
Building native extensions. This could take a while...
ERROR: Error installing debugger-linecache:
ERROR: Failed to build gem native extension.
/Users/jordanscales/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for vm_core.h... no
checking for vm_core.h... no
Makefile creation failed
**************************************************************************
No source for ruby-1.9.3-p194 provided with debugger-ruby_core_source gem.
**************************************************************************
*** 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/jordanscales/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
--with-ruby-dir
--without-ruby-dir
--with-ruby-include
--without-ruby-include=${ruby-dir}/include
--with-ruby-lib
--without-ruby-lib=${ruby-dir}/lib
Gem files will remain installed in /Users/jordanscales/.rvm/gems/ruby-1.9.3-p194/gems/debugger-linecache-1.0.1 for inspection.
Results logged to /Users/jordanscales/.rvm/gems/ruby-1.9.3-p194/gems/debugger-linecache-1.0.1/ext/trace_nums/gem_make.out
trunk ☺
Any help would be extremely appreciated, I have been searching but cannot find a working solution.
this may help you, it works for me
gem install debugger-linecache -v '1.1.2' -- --with-ruby-include=$rvm_path/src/ruby-1.9.3-p286/
This error means that the selected version of debugger does not support your current Ruby version. There are two solutions:
Update the debugger gem via bundle update debugger. New versions of debugger are backward-compatible with old Ruby versions, so this is the best way to fix it.
Downgrade your Ruby version.
Update/Install the gem debugger-ruby_core_source,
gem install debugger-ruby_core_source
it has been corrected here : https://github.com/cldwalker/debugger-ruby_core_source/pull/7
The problem was that I was using gemsets incorrectly. I knew not having permissions were an issue, as under RVM I shouldn't need sudo to install anything.
rvm gemset use global and then a bundle install did the trick.
From the below link:
https://github.com/cldwalker/debugger/issues/50
I have installed gem ruby-debug19 and problem solved for me as below:
$ bundle
... -> failed to build debugger-linecache
$ gem install ruby-debug19
$ bundle
... -> all is fine
In my case problem was not related to debugger-linecache directly. Either try upgrading debugger-ruby_core_source or downgrade Ruby by few patchlevels.
I've executed bundle update debugger-linecache. Although I had its newest version in Gemfile.lock, debugger-ruby_core_source has been upgraded to 1.1.5 and debugger-linecache has stopped complaining.
I installed debugger-ruby_core_source gem, based on perusing old answers here: https://github.com/cldwalker/debugger/issues/12
If you are using rvm, then make sure the path lead to ruby, in rvm its rubies folder
$rvm_path/rubies/ruby-1.9.3-p448
gem install debugger-linecache -v '1.1.2' -- --with-ruby-include=$rvm_path/rubies/ruby-1.9.3-p448
Your Gemfile.lock wasn't written with the same Ruby that you're trying to bundle against.
bundle update should work by making Bundler look at different versions.
manually build it. it works for me
https://gist.github.com/4060260

Why does installing Nokogiri on Mac OS fail with libiconv is missing?

I've been trying to install Nokogiri on Mac OS 10.9.3 and whatever I try, the install fails in the end with the following error message:
$ sudo 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.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib
Building native extensions with: '--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.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib'
This could take a while...
Building nokogiri using packaged 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 --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.14/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.14/lib
Building nokogiri using packaged libraries.
checking for iconv.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
checking for libiconv_open() in iconv.h... no
checking for libiconv_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=/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
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/gems/nokogiri-1.6.2.1/ext/nokogiri/gem_make.out
After following a lot of help found around the web including building and installing libxml2 and libxslt using brew and building libiconv from the sources (as described in "Installing Nokogiri"), the error remains the same.
When trying to run the installation for Nokogiri, libxml2 and libxslt seem to be found fine, but not libiconv.
Anyone with a better knowledge of these things know how to get Nokogiri installed?
I had the same issue. Unfortunately the "Installing Nokogiri" doesn't cover Iconv issues. Here's how I resolved the issue.
First install homebrew, it'll make your life easier. If you already have it installed, be sure to grab the latest formulae by updating like so:
brew update
Note: In OSX 10.9+ you may need to install xCode command tools to allow you to install libiconv.
xcode-select --install
then install a newer version of libiconv
brew install libiconv
then install your gem
gem install nokogiri -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14
Try using the system libraries. OSX comes with libiconv in newer versions, but the defaults install script seems to have a problem
gem install nokogiri -- --use-system-libraries
Edit: If using bundler, as mentioned by Geoff you can do:
bundle config build.nokogiri --use-system-libraries
#Cory's solution contains the correct answer, but the solution on Mavericks is actually much simpler than the top solution so I'm reposting with only the necessary steps.
On Mavericks (OSX 10.9+):
Install Xcode Command Line Tools:
xcode-select --install
then install your gem:
gem install nokogiri
I was finally able to solve this problem. None of the above solutions completely fixed it for me.
I was getting this error when trying to gem install nokogiri on OSX Lion 10.7.2. First of all, this error masks the real problem by saying libiconv is missing, because you will get the same error even if nokogiri can't find libxslt or libxml2, which in my case, it couldn't.
So I followed the instructions on http://nokogiri.org/tutorials/installing_nokogiri.html under the Homebrew section (slightly modified to account for a more current version of libxml2):
brew install libxml2
brew link libxml2
# install libxslt from source
wget ftp://xmlsoft.org/libxml2/libxslt-1.1.26.tar.gz
tar -zxvf libxslt-1.1.26.tar.gz
cd libxslt-1.1.26
./configure --prefix=/usr/local/Cellar/libxslt/1.1.26 --with-libxml-prefix=/usr/local/Cellar/libxml2/2.7.8
make
sudo make install
At this point I followed the directions on the nokogiri site and tried
gem install nokogiri -- --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26
However, this still failed because when building libxslt from source, it installs the /include folder in a funky place. So you need to specify the lib and include folders separately like so:
gem install nokogiri -- --with-xslt-lib=/usr/local/Cellar/libxslt/1.1.26/lib --with-xslt-include=/usr/local/Cellar/libxslt/1.1.26/include/libxslt
This still didn't work (same libiconv error), so I tried to specify all three required libraries (libxslt, libxml2 and libiconv):
gem install nokogiri -- --with-xslt-lib=/usr/local/Cellar/libxslt/1.1.26/lib --with-xslt-include=/usr/local/Cellar/libxslt/1.1.26/include/libxslt --with-iconv-dir=/usr/local/Cellar/libiconv/1.14 --with-xml2-dir=/usr/local/Cellar/libxml2/2.7.8
Now I got a different error! It was still an error but at least it was different. The make process failed with:
in /opt/local/lib/libz.1.dylib, file was built for unsupported file format which is not the architecture being linked (x86_64) for architecture x86_64
Uhh, what? After a lot of googling, I came across this miracle post: http://www.refresherate.com/2010/01/08/fixing-ld-warning-in-usrlocalliblibz-dylib-file-is-not-of-required-architecture/
Apparently OSX Lion ships with some bad versions of the libz library (libz.dylib, libz.1.dylib, libz.1.2.4.dylib) and and they need to be replaced with the latest versions from the Xcode SDK. The article explains it better than I can so read the above link for specific instructions.
Once these were replaced, I ran
gem install nokogiri -- --with-xslt-lib=/usr/local/Cellar/libxslt/1.1.26/lib --with-xslt-include=/usr/local/Cellar/libxslt/1.1.26/include/libxslt --with-iconv-dir=/usr/local/Cellar/libiconv/1.14 --with-xml2-dir=/usr/local/Cellar/libxml2/2.7.8
again and all was well. I hope this helps someone else.
Just adding my voice to the crowd, but mkmf.log said something about not being able to find symbols for x86_64 architecture. I stumbled across this solution:
sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri -- --use-system-libraries
May not solve anything for the original asker, but this may help someone.
Side Note: nokogiri has been my highest barrier to using ruby applications. Every time someone depends on a different version I have to figure out how to build it. And my problem is different every time.
gem install nokogiri -v '1.6.6.2' -- --use-system-libraries --with-xml2-include=$(brew --prefix libxml2)/include/libxml2
this worked for me on macos.
It works also with version 1.6.6.4
I'm using..
OS X 10.9.4
Homebrew 0.9.4
Here is my summery from this thread to successfully install nokogiri, fixing missing libiconv.
Install Homebrew http://brew.sh/
Or update to latest using command below
brew update
Install libxml2 libxslt
brew install libxml2 libxslt
Link both libxml2 libxslt
brew link libxml2 libxslt
If you get warning to use --force, just use command below
brew link --force libxml2 libxslt
Install xCode command tools to enable you to install libiconv
xcode-select --install
Install libiconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
tar xvfz libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local/Cellar/libiconv/1.13.1
make
sudo make install
Final step, install nokogiri!
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.8.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.8.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include --with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
I solved this on Yosemite running Ruby 2.1.4 by
ensure you have xCode 6.1 installed, then
xcode-select --install, then
In the AppStore click on updates and install the most recent version of the command-line tools (which apparently xcode-select --install does't do - sigh)
then bundle install worked as normal.
I also did a brew install libiconv too but I am not convinced that step was needed.
I tried many things but nothing worked for me. Then I finally found the iconv documentation and it saved my day!
Looking in the mkmf file, it apear that nokogiri (or gem, I don't know) try to find dependencies in /op/local/. For me it's not the right path to search them for.
Forcing nokogiri to find the libs at the right place (I use homebrew) did the trick for me :
$ gem install nokogiri -- --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-xml2-dir=/usr/local/Cellar/libxml2/2.7.8/
Maybe there is something to fix in nokogiri...
HTH,
libiconv was removed from Homebrew 0.9 Now it's recommended to compile libiconv from source, then reference the install when you install the nokogiri gem. See the Nokogiri install instructions under the Homebrew 0.9 section on the Nokogiri install page
Look in the mkmf.log file in the gem's build directory (e.g. /Library/Ruby/Gems/1.8/gems/nokogiri-1.4.4/ext/nokogiri/mkmf.log). That has a lot more info. In my case when I hit this it was that Nokogiri specifically adds /opt/local/lib to the library search path and GNU Backgammon had installed an incompatible libiconv there.
Assuming you installed libxml2 and libxslt with MacPorts, then you might still be getting this error due to a mismatch of the order of include paths and link paths used by the call to have_func('iconv_open', 'iconv.h')
Simple (patch) solution: delete libiconv.* in /usr/local/lib
$ gem install nokogiri -- --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-xml2-dir=/usr/local/Cellar/libxml2/2.7.8/
same as above, this is the solution for homebrew and using gem install (apply changes depends on your version)
however, if you use Gemfile and bundle install, you should apply the bundle config before you install, here the code
$ bundle config build.nokogiri --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26 --with-xml2-dir=/usr/local/Cellar/libxml2/2.7.8/ --with-iconv-dir=/usr/local/Cellar/libiconv/1.14
again, apply changes depends on your version
hope this will help you.
credit: https://gist.github.com/1344331
I had similar trouble on Mountain Lion. Turns out I had installed libiconv via rvm package previously and this is no longer necessary for ruby 1.9.3/Mountain Lion/nokogiri.
Following the advice of https://rvm.io/packages/, I deleted my $rvm_path/usr directory and rebuilt ruby 1.9.3. Thereafter installing nokogiri was a simple gem install. No messing with brew/macports/manual source installs!
You could also do this on Mavericks:
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
Just make sure you have xcode installed
I was fighting with Nokogiri for a while today on OS X 10.10 Yosemite
My environment was messed up for some reason.
which bundle and which gem were giving me /usr/bin/bundle and /usr/bin/gem instead of ~/.rbenv/shims/gem
What helped correct it for me was sudo rm -i /usr/bin/gem /usr/bin/bundle
After that I:
1. switched back to my project directory
2. uninstalled the dependent
3. (re)-installed the dependent libs: did a brew install libxml2 libiconv libxslt
4. installed my ruby version fresh (with rbenv)
5. did gem install bundler
6. and bundle install ran without any problems.
Nokogiri was fine after that.
For reference:
╰─% cat .bundle/config
---
BUNDLE_PATH: vendor/bundle
BUNDLE_DISABLE_SHARED_GEMS: '1'
BUNDLE_JOBS: 4
╰─% which ruby bundle gem
~/.rbenv/shims/ruby
~/.rbenv/shims/bundle
~/.rbenv/shims/gem
This one worked for me
sudo env ARCHFLAGS="-arch x86_64" gem install nokogiri:1.6.6.2 -- --use-system-libraries --with-xml=/usr/local/Cellar/libxml2/2.9.3/ --with-iconv-dir=/usr/local/Cellar/libiconv/1.14
You need to upgrade your homebrew to 0.9
then follow these steps
brew install libxml2 libxslt
brew link libxml2 libxslt
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
tar xvfz libiconv-1.13.1.tar.gz
cd libiconv-1.13.1
./configure --prefix=/usr/local/Cellar/libiconv/1.13.1
make
sudo make install
sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.0/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
You should double check the folder library version.
HOMEBREW USERS
Correct solution to fix this problem if you are using homebrew:
xcode-select --install
Choose "Get Xcode" from the dialog box.
brew unlink libiconv
gem install nokogiri
The xcode-select step fixes your Xcode installation and Xcode Command Line Utils installation. I found that I didn't have /usr/include/iconv.h due to some kind of problem with O/S upgrades or restores from backups. If you don't have that header file and /usr/lib/libconv.dylib after running xcode-select then you most likely need to drag Xcode from the Application folder to the trash and reinstall and then manually download the Command Line Tools for Xcode from https://developer.apple.com/downloads/index.action and install that.
Then you need to unlink the libiconv from homebrew. You don't need this. And clang will actually pick up /usr/local/include/iconv.h over /usr/include/iconv.h and will #define iconv_open to libiconv_open but then link against /usr/lib/libiconv.dylib which does not have libiconv_open which is what causes the mkmf failures to find libiconv. What you need to do is remove the linking in of iconv.h so that nokogiri will not find it.
Then just build nokogiri normally.
For new users, all you should need to do is install xcode with xcode-select and install nokogiri, but if you've found this question then presumably you've got a botched installation and not a fresh install of Mavericks.
Some of the other answers here are definitely incorrect. Most of them attempt to use libiconv out of homebrew which is entirely unnecessary. The answers that brew link libiconv are actually causing the problem where clang becomes confused and tries to read a homebrew header file and link against the system libraries. The answers which suggest --use-system-libraries are poor because nokogiri needs to be linked against its bundled libxml2 and libxslt libraries because other versions of those libraries are incompatible with it. The answers which want you to compile from sources are just hopelessly overly complicated.
TL;DR:
Upgrade and/or repair your Xcode installation
Unlink your homebrew libiconv since trying to use that only causes problems
Build nokogiri normally
RVM USERS
Old RVM installations may have a libiconv hiding in your rvm directories somewhere which are conflicting with your system libraries. See https://stackoverflow.com/a/11809261/506908 for more information.
MacPorts USERS
If you have /opt/local/lib/libiconv.dylib then nokogiri adds that path to the list of directories that it searches for and it will find the MacPorts installation similar to how it picks up the homebrew libiconv and conflicts with the system libraries. You can try:
sudo port uninstall libiconv
If that fails due to dependencies then you can try linking against the MacPorts version directly (untested):
gem install nokogiri -- --with-iconv-dir=/opt/local
I ran into this, this morning... after an upgrade to Mavericks. We did many things. However if anyone is having this issue here are some things to try.
I ran 'xcode-select --install' then got the command line tools installed (surprised this didn't update on the OS ugrade).
I ran 'rvm implode' (I will build it back up later).
We pieced together two error output files:
~/.vagrant.d/gems/gems/nokogiri-1.6.3.1/ext/nokogiri/gem_make.out
~/.vagrant.d/gems/gems/nokogiri-1.6.3.1/ext/nokogiri/tmp/x86_64-apple-darwin12.5.0/ports/libxml2/2.8.0/configure.log
Which seemed to indicate that the c compiler was using a surprising setting.
I ran 'env'
Output contained:
...
CXX=/usr/local/opt/apple-gcc42/bin/g++-4.2
...
CC=/usr/local/opt/apple-gcc42/bin/gcc-4.2
...
These files didn't exist on the file system...
After all of these changes moving to a new terminal windows (so everything was fresh). Installation of vagrant-berkshelf (which in turn installs nokogiri) worked fine.
NOTE: when running 'env' in the fresh window there was no longer a setting for CC or CXX...
Unsure on the key part of this, or if order matters, but tried to recreate the parts that seemed to play a role in getting this to work.
According to the documentation, as of OSX 10.9 and Homebrew 9.5+, you are probably missing the development tools.
Nokogiri installation
Troubleshooting
If you have problems mentioning libiconv missing that looks something like this:
Installing nokogiri (1.6.2.1) Building nokogiri using packaged libraries.
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/local/rvm/rubies/ruby-2.0.0-p0/bin/ruby extconf.rb
Building nokogiri using packaged libraries.
checking for iconv.h... yes
checking for iconv_open() in iconv.h... no
checking for iconv_open() in -liconv... no
checking for libiconv_open() in iconv.h... no
checking for libiconv_open() in -liconv... no
-----
libiconv is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies.
-----
*** extconf.rb failed ***
Then you are probably missing the right developer tools. This is a really easy fix:
brew unlink gcc-4.2 # you might not need this step
gem uninstall nokogiri
xcode-select --install
gem install nokogiri
This is verified working on OSX 10.9 w/ xcode’s clang compiler.
I got this issue when I upgraded my Mac OS to Yosemite. I was able to solve this issue by doing:
xcode-select --install
brew uninstall libiconv
brew install libiconv
gem install nokogiri
I had a similar issue and the accepted answer used to work for me. Now, however I have been seeing a new error message where a gmkdir command is missing as in this question:
gem install nokogiri -v '1.5.11' failed due to make: /usr/local/bin/gmkdir: No such file or directory
What worked for me was first a little cleanup:
brew uninstall libiconv
brew uninstall libxml2
brew uninstall libxslt
And then brew unlink libiconv and whatever else you need to unlink (check with brew doctor). Then, the magic two lines (copied from the linked answer):
brew install coreutils
gem install nokogiri
Simple steps to follow before you start uninstalling and installing anything.
Check if you have CLT (command line tools installed):
brew config
see the CLT version here if its installed no need for reinstallation.
This means the issue is with permission you have reinstall only bundler gem make its not sudo.
Uninstall bundler with
gem uninstall bundler
reinstall gem bundler
gem install bundler
Most important point here is the permission under which bundler gem is installed it should never be sudoed.
First of all make sure you follow the installation guide on nokogiri: http://nokogiri.org/tutorials/installing_nokogiri.html
After having followed the guide I still had this issue. This is how I solved it:
First of all I installed iconv using homebrew:
brew install iconv
Then I uninstalled ruby, luckily this is very easy with rvm:
rvm uninstall 1.9.2
Then I had to reinstall ruby with the following options:
CC=gcc-4.2 rvm install 1.9.2-p290 --with-iconv-dir=/usr/local/Cellar/libiconv/1.13.1
Then I create a gemset with the new ruby version:
rvm use 1.9.2#coolproject
Then I can finally install nokogiri like this:
gem install nokogiri -v=1.4.4 -- --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
In my case, (as with scotchi) the build failed because of an incompatible iconv library in /opt/local/lib.
By default, theNokogiri build process looks at /opt/local first.
To force it to use a different install directory, /usr/local for example, do:
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
This blog post proposes to install libiconv manually.
Subsequently, nokogiri can be installed with a number of switches telling it where to find libiconv (see the blog post).
As a side note: After installing nokogiri, I managed to install gollum (installation of which also failed because it could not find iconv). Now I am still facing problems though, because when I start up gollum, Python crashes.
$ gem install iconv # works but it is missing an iconv.so file in ruby 2.0.0-p247
$ ls -1 2.0.0-p0/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/*/*/*.so
2.0.0-p0/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/ext/iconv/iconv.so*
2.0.0-p0/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/lib/iconv/iconv.so*
$ ls -1 2.0.0-p247/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/*/*/*.so
2.0.0-p247/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/ext/iconv/iconv.so*
NOTE THE MISSING /lib/iconv/iconv.so file in 2.0.0-p247 that is present in 2.0.0-p0 gems installation.
$ rbenv version
2.0.0-p247 (set by /home/XXX/tmp/.ruby-version)
$ rbenv which gem
/home/XXX/.rbenv/versions/2.0.0-p247/bin/gem
$ gem --version
1.8.25
$ rbenv which pry
/home/XXX/.rbenv/versions/2.0.0-p247/bin/pry
$ pry
[1] pry(main)> require 'iconv'
LoadError: cannot load such file -- iconv/iconv.so
from /home/XXX/.rbenv/versions/2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/custom_require.rb:36:in `require'
Copy the file over
$ pushd ~/.rbenv/versions/
$ cp 2.0.0-p247/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/ext/iconv/iconv.so 2.0.0-p247/lib/ruby/gems/2.0.0/gems/iconv-1.0.3/lib/iconv/
NOW IT WORKS!
$ pry
[1] pry(main)> require 'iconv'
=> true
I had to install gcc first before running ./configure --prefix=/usr/local/Cellar/libiconv/1.13.1

Trying to install ruby-filemagic on Snow Leopard using brew rather than ports

I'm trying to install ruby-filemagic.
I tried sudo gem install ruby-filemagic -v 0.2.2 and got:
ERROR: Error installing ruby-filemagic:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for magic_open() in -lmagic... no
*** 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
...
According to this : http://blog.elctech.com/2009/08/31/installing-ruby-filemagic-on-macos-x-and-ubuntu/
I need the opt-dir setting. Opt is for mac ports right? And I'm using homebrew.
Any suggestions as to where to go from here would be great.
Installing directly from the gem still didn't work for me but the following command did:
sudo env ARCHFLAGS="-arch x86_64" gem install ruby-filemagic -- --with-magic-include=/usr/local/include --with-magic-lib=/usr/local/lib/
you don't have to make your own formula, it's there in libmagic.
brew install libmagic
brew link libmagic
then, for whatever reason the gem install didn't work but cloning the lib and running
ruby extconf
make
make install
worked. godspeed!
This worked for me on 10.9: Install libmagic on Mac OS X via homebrew
In short:
brew install libmagic
brew link libmagic
# If the link is already created is going to fail, dont worry about that
env ARCHFLAGS="-arch x86_64" gem install ruby-filemagic -- --with-magic-include=/usr/local/include --with-magic-lib=/usr/local/lib/
Yes, the commands from that tutorial are specific (in some ways) to MacPorts. The guide suggests first installing the necessary library via MacPorts, and then installing the gem that uses that library. At a glance, you don't have the library, so the extension can't be built for the gem. Also at a quick glance, Homebrew doesn't appear to have that library available for installation - though I'm not 100% sure of that.
Follow-up: From the same blog, here's his advice for how to do it with Homebrew. In a nutshell, you need to create your own installation of the library you need and then you should be ok. By the way, he suggests sudo, but you probably don't need or want that with Homebrew (if you use Homebrew in the normal way).

Resources