`gem install therubyracer` fails on Mac OS X Lion - ruby

I would appreciate some help in getting gem install therubyracer to work. Here is the error:
$ gem install therubyracer
Building native extensions. This could take a while...
ERROR: Error installing therubyracer:
ERROR: Failed to build gem native extension.
/Users/david/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for main() in -lobjc... yes
*** 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/david/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
--with-objclib
--without-objclib
extconf.rb:15:in `<main>': undefined method `include_path' for Libv8:Module (NoMethodError)
Here are some notable steps that I ran before the error. They worked fine:
$ gem install libv8
$ brew install v8
My environment is:
Mac OS X Lion 10.7.4
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0] (via rvm)
V8 version 3.9.24 (via homebrew)

This worked for me:
$ gem uninstall libv8
$ gem install therubyracer
(A big thanks to http://www.ruby-forum.com/topic/4306127)

gem uninstall libv8
brew install v8
gem install therubyracer

But, why is this happening, you ask? And why does uninstalling libv8 and reinstalling therubyracer fix the problem?
The answer is at the bottom of the error message (from orig post). Ignore the stuff about
probably lack of necessary libraries and/or headers
This is an incorrect assumption by whoever wrote that error message. At the bottom, you see what Ruby has to say about it:
undefined method `include_path' for Libv8:Module
In my case, I was trying to install therubyracer-0.9.8 with bundle install, and for some reason, it was trying to use my copy of libv8-3.11.8.13, which had been installed at some point, probably as a dependency of some other gem.
I don't know why it was trying to use the newer version, because therubyracer.gemspec contains s.add_dependency "libv8", "~> 3.3.10". And my Gemfile.lock says to use libv8 (3.3.10.2). But alas, that is indeed what was happening.
And it's true that Libv8:Module does not have the method include_path in libv8-3.11.8.13, but it does in libv8-3.3.10.2
So that is why uninstalling all of your versions of libv8 and then re-installing therubyracer works. Because all the versions of libv8 that do not have the method include_path are removed completely, and the libv8 that does have the method include path is reinstalled when you reinstall of therubyracer.

Considering none if the above worked for me 100%, I thought I'd post what did (as part of a rails project):
gem uninstall libv8
bundle update therubyracer
This made sure I got the latest therubyracer, and also a more recent version of libV8, and seem to fix the multiple issues I was hitting, from missing libv8.a files, to undefined methods.

At last I use therubyracer 0.11.0beta5 as a solution.
Using therubyracer (0.11.0beta5)
add following on Gemfile
gem 'therubyracer', '~> 0.11.0beta5'
group :libv8 do
gem 'libv8', "~> 3.11.8"
end
then bundle install
Mac OSX 10.8 Moutain Lion

If you need 0.11.3 and it's failing give this a shot for Mac OS X 10.9...
gem uninstall libv8
brew install v8
gem install libv8 -- --with-system-v8
gem install therubyracer -v '0.11.3' -- --with-system-v8
See this issue for more details.
You probably don't need the -- --with-system-v8 on the last line but I did it just to be safe since I saw it start doing Fetching: libv8-3.11.8.17-x86_64-darwin-13.gem (1%) when I ran the command...
Anyhow, it worked for me when all the other things did not.

For anyone encountering this issue on Mac OSX 10.8 Mountain Lion when attempting to upgrade their Gemfile with gem 'therubyracer', '0.11.0', just upgrading the system libv8 gem worked for me (no uninstallation of any other gem necessary):
$ gem update libv8
$ bundle install
Edit
If you use Travis-CI (or other CI tools located on other servers, I assume), you will need to explicitly add the libv8 gem to your Gemfile as well:
Gemfile
gem 'libv8', '3.11.8.3'
then bundle install as usual. Just note that libv8 can take a significant amount of time to install and I've noticed that it may end up being the cause of going over Travis CI's timeout limits, causing your build to fail. You can mitigate this slightly be not including development environment gems in your builds:
.travis.yml
# ...
bundler_args: --binstubs=./bundler_stubs --without development
Update
Yep, pretty much all my Travis builds timeout and fail because of this. If anyone knows a way to solve this problem (I would hope "downgrade therubyracer" is a last resort), please leave a comment!
Update 2
This may not work for all apps, but it seems that my Rails 3.2.9 apps didn't actually need therubyracer or libv8 after all. After removing those gems from my Gemfile, I confirmed that my specs passed, pushed again to Travis and it built successfully. So, I guess getting rid of those gems (if you're not sure you actually need them) is at least worth a try.
Update 3
Thanks to Paul Annesley for confirming that if you're on Mac OS X 10.8 Mountain Lion, you don't need therubyracer gem at all since the OS already comes bundled with Apple JavaScriptCore, its own Javascript runner. At the time of the original answer, I was on Snow Leopard and hence needed it.

For me, removing the Gemfile.lock file and running bundle install worked it's magic.

OSX 10.8.2, ruby 1.9.3p125
None of the above worked for me... I got tired of trying to find the right gem for my environment, so I just soft linked to the g++ target this things was missing:
sudo ln -s `which g++` /usr/bin/g++-4.2
Not as helpfully for remote deployments, but get the job done on my workstation.

I got a similar issue, but it was also complaining about not finding g++-4.2. I did have XCode command line tools installed, but it was looking for /usr/bin/g++-4.2, I had g++ (which was a symbolic link pointing to llvm-g++-4.2). Anyway, I just created a symbolic link to g++ and tried the bundle install again... it worked!
$ cd /usr/bin
$ sudo ln -s g++ g++-4.2

Had the same error, this worked for me:
From console: gem uninstall libv8
In your Gemfile, add the following:
gem 'therubyracer', :platforms => :ruby, :require => 'v8'
gem 'libv8', '~> 3.11.8' # Update version number as needed
From console: bundle install
If you were in the middle of upgrading therubyracer gem, you may want to run bundle update therubyracer after that as well. (Consider specifying a version number)
This was on Mac 10.6 (Snow Leopard).

Related

ruby gem nokogiri version 1.12.5 install error: 'gumbo.h' file not found

I tried changing the gemfile to use a newer version of nokogiri as well as resolve dependencies by brew installing libxml2 and libslt, but nothing worked. Here is the error message:
gumbo.c:32:10: fatal error: 'gumbo.h' file not found
#include "gumbo.h"
^~~~~~~~~
1 warning and 1 error generated.
make: *** [gumbo.o] Error 1
I had the same issue. Not a satisfying answer, but I uninstalled everything and did a clean install using rbenv and it worked.
I had a similar problem. After reading the nokogiri installation instructions, I learned something!
Nokogiri provides precompiled binaries for most things. Now if you switch from Mac to Linux or vice versa, your Gemfile.lock may have a platform list which doesn't include your current platform.
The command that fixed it for me was
bundle lock --add-platform arm64-darwin
Then, bundle just downloaded the precompiled version.
My recommendation is to work out how to install the precompiled version for your platform. When I ran gem install nokogiri that is what happened, but because of the platform list in the Gemfile.lock it wasn't doing that and instead wanted to compile it.
The solution for me on my M1 Macbook was by using rbenv but first:
Uninstall bundler: gem uninstall bundler
Uninstall rbenv: rbenv uninstall YourRubyVersion and then brew uninstall rbenv
(YourRubyVersion you can find it by executing ruby -v)
Delete the Gemfile.lock file.
After that:
brew install rbenv
rbenv install RubyVersion
rbenv init
rbenv global RubyVersion
bundle install

How to install therubyracer gem on 10.10 Yosemite?

I don't manage to install therubyracer gem on Yosemite 10.10.
Here is the log:
11:53 $ gem install libv8 -v '3.16.14.3' -- --with-system-v8
Building native extensions with: '--with-system-v8'
This could take a while...
Successfully installed libv8-3.16.14.3
Parsing documentation for libv8-3.16.14.3
Installing ri documentation for libv8-3.16.14.3
Done installing documentation for libv8 after 0 seconds
1 gem installed
02:05 $ gem install therubyracer -v '0.12.1' -- --with-system-v8
Building native extensions with: '--with-system-v8'
This could take a while...
ERROR: Error installing therubyracer:
ERROR: Failed to build gem native extension.
/usr/local/var/rbenv/versions/2.1.2/bin/ruby extconf.rb --with-system-v8
checking for main() in -lpthread... yes
checking for main() in -lobjc... yes
checking for v8.h... 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=/usr/local/var/rbenv/versions/2.1.2/bin/ruby
--with-pthreadlib
--without-pthreadlib
--with-objclib
--without-objclib
--enable-debug
--disable-debug
--with-v8-dir
--without-v8-dir
--with-v8-include
--without-v8-include=${v8-dir}/include
--with-v8-lib
--without-v8-lib=${v8-dir}/lib
/usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/libv8-3.16.14.3/ext/libv8/location.rb:50:in `configure': You have chosen to use the version of V8 found on your system (Libv8::Location::System::NotFoundError)
and *not* the one that is bundle with the libv8 rubygem. However,
it could not be located. please make sure you have a version of
v8 that is compatible with 3.16.14.3 installed. You may
need to special --with-v8-dir options if it is in a non-standard
location
thanks,
The Mgmt
from /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/libv8-3.16.14.3/lib/libv8.rb:7:in `configure_makefile'
from extconf.rb:32:in `'
extconf failed, exit code 1
Gem files will remain installed in /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/therubyracer-0.12.1 for inspection.
Results logged to /usr/local/var/rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/therubyracer-0.12.1/gem_make.out
gem uninstall libv8
brew install v8
gem install therubyracer
gem install libv8 -v '3.16.14.3' -- --with-system-v8
this is the only way it worked for me on 10.10 (ruby 2.1.2)
Or try gem install libv8 -v 'XX.XX.XX' -- --with-system-v8 adding the version of the gem :)
UPDATE for Mac OS Catalina:
brew tap homebrew/versions
brew install v8#3.15
brew link --force v8#3.15
gem install libv8 -v 'XX.XX.XX' -- --with-system-v8
gem install therubyracer
git clone https://github.com/cowboyd/libv8.git
cd libv8
bundle install
bundle exec rake clean build binary
gem install pkg/libv8-3.16.14.3-x86_64-darwin-12.gem #note that libv8 version may change, so tab through files in pkg/, also remember to use the one with version specified
then just bundle your project gems
this is the only way it worked for me on 10.10 (ruby 2.1.2)
None of the answers work for me this time. I have too use this:
brew tap homebrew/versions
brew install v8-315
gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315
bundle install
Seen on the rubyracer Github issues.
Hope it helps someone else.
Maybe it will be useful for someone but I had problems installing therubyracer (because of the problems with libv8) the solution was to uninstall all the libv8 that I had installed. Install therubyracer
$ gem uninstall libv8
$ gem install therubyracer -v '0.12.0'
Fetching: libv8-3.16.14.7-x86_64-darwin-14.gem ( 57%)
Fetching: libv8-3.16.14.7-x86_64-darwin-14.gem (100%)
Successfully installed libv8-3.16.14.7-x86_64-darwin-14
Building native extensions. This could take a while...
Successfully installed therubyracer-0.12.0
2 gems installed
I hope this helps someone.
It seems like this has been fixed upstream. What worked for me and #aurels and #Mike Causer and #Juanda was:
bundle update libv8
This worked for me very well on my Yosemite and Ruby 2.1.5 (Ruby through RVM)
gem install libv8 -v '3.16.14.3' -- --with-system-v8
Earlier it was giving me error Gem::Ext::BuildError: ERROR: Failed to build gem native extension. for libv8 gem version 3.16.14.3
Only this works for me in my Yosemite, Ruby 2.1.2:
gem install libv8 -v '3.16.14.3' -- --with-system-v8
brew link --overwrite v8-315 --force
gem install therubyracer -v '0.12.2' -- --with-system-v8
I was able to proceed with ruby racer after rm Gemfile.lock
beforehand:
I installed v8 via brew install v8, and then did gem install libv8 -v '3.16.14.3' -- --with-system-v8
and I am running 10.10 Yosemite
They have corrected this issue in the most recent version of libv8. See: https://github.com/cowboyd/libv8/issues/123
You should install from the github repo, in rails I added a line to my gemfile like this gem "libv8", git: "git://github.com/cowboyd/libv8.git", submodules: true
EDIT:
This apparently only solves some of the problem. I installed the new version of libv8, but now the rubyracer is still looking for the other one I think? Still looking into it.
I had the same issue on Yosemite. My solution is similar to what appears above.
Use gem uninstall libv8 to remove anything that might be installed.
Leave therubyracer in your Gemfile, but remove any explicit reference to libv8.
Run bundle install.
libv8 then installed fine as a dependency.
Updated answer for 2018.
I'm on High Sierra, on Homebrew 1.6.1
brew install v8-315
gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8#3.15/
Is what worked for me.
Credit goes to #coding-addicted for his original answer.
After hours of trying simply upgrading ruby worked:
brew install ruby
and then adding the following to gem file:
gem 'libv8'
gem 'therubyracer'
A heads up to anyone that might have been having my issue: I ended up uninstalling my ruby version in RVM and then reinstalling it. That seemed to use the correct dependancies in the latest version of xcode tools for compiling ruby.
rvm list
rvm uninstall ruby-x.x.x
rvm install ruby-x.x.x
I did the following
gem install therubyracer
which now installs therubyracer 0.12.1 which installs the dependency libv8 (3.16.14.7 x86_64-darwin-14) which installed with no errors.
I did this using ruby 2.1.5 which I installed via:
CC=/usr/bin/gcc rbenv install 2.1.5
which I did after running brew upgrade ruby-builds.
After installing ruby 2.1.5, I also ran
gem upgrade --system
to get rubygems-update 2.4.5
this happens due to some conflicts with the libv8 as well, although you can just assign a version to the rubyracer and it will be installed:
change the following in the gemfile:
gem 'therubyracer', '~> 0.12.1'
and do bundle install
What worked for me, based on the following comment,
https://github.com/cowboyd/therubyracer/issues/304#issuecomment-62046085
was to remove Gemfile.lock and then run bundle install
This solution worked for me following Jakub Troszok's solution above with just a minor change
gem uninstall libv8
gem install therubyracer -v '0.12.1'
Fetching: libv8-3.16.14.19-x86_64-darwin-18.gem (100%)
Successfully installed libv8-3.16.14.19-x86_64-darwin-18
Building native extensions. This could take a while...
Successfully installed therubyracer-0.12.1
Parsing documentation for libv8-3.16.14.19-x86_64-darwin-18
Installing ri documentation for libv8-3.16.14.19-x86_64-darwin-18
Parsing documentation for therubyracer-0.12.1
Installing ri documentation for therubyracer-0.12.1
Done installing documentation for libv8, therubyracer after 0 seconds
2 gems installed
gem install libv8 -v '3.16.14.17' -- --with-system-v8 (if the libv8 version required for your project is different from the one installed by rubyracer)
bundle install
Using homebrew's directory of v8 for --with-v8-dir=/usr/local/Cellar/v8#3.15/3.15.11.18_1, instead of /usr/local/opt/v8-315, is what worked for me, in coding addicted's answer.
This is visible in the Summary of the brew install command, brew install v8-315.

Ruby Gem install Json fails on Mavericks and Xcode 5.1 - unknown argument: '-multiply_definedsuppress'

I was trying run gem install json and got the following error
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling generator.c
linking shared-object json/ext/generator.bundle
clang: error: unknown argument: '-multiply_definedsuppress' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
make: *** [generator.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /opt/boxen/repo/.bundle/ruby/2.0.0/gems/json-1.8.0 for inspection.
Results logged to /opt/boxen/repo/.bundle/ruby/2.0.0/extensions/universal-darwin-13/2.0.0/json-1.8.0/gem_make.out
I'm using:
Os X: 10.9.2
Xcode: 5.1 Build version 5B130a
Command Line Tools (CLT): 5.1.0.0.1.1393561416
Ruby: ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]
Ruby Gem: 2.2.2
GCC: 4.2.1 Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
I am encountering the exact same problem after updating Xcode to 5.1 and news from Apple aren't good. From Xcode 5.1 Release Notes:
The Apple LLVM compiler in Xcode 5.1 treats unrecognized command-line options as errors. This issue has been seen when building both Python native extensions and Ruby Gems, where some invalid compiler options are currently specified.
Projects using invalid compiler options will need to be changed to remove those options. To help ease that transition, the compiler will temporarily accept an option to downgrade the error to a warning:
-Wno-error=unused-command-line-argument-hard-error-in-future
To workaround this issue, set the ARCHFLAGS environment variable to downgrade the error to a warning.
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install GemName
It seems that all gems violating the compiler options must be updated to use valid options. It is explicitly stated that: This option [downgrading error to warning] will not be supported in the future.
The clang note we are seeing (this will be a hard error (cannot be downgraded to a warning) in the future) corresponds to the change announced in the release notes.
To answer your question specifically, use the following to install the json gem:
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install json
Note, however, that this is only a temporary fix.
One-liner to fix that
curl https://gist.githubusercontent.com/Paulche/9713531/raw/1e57fbb440d36ca5607d1739cc6151f373b234b6/gistfile1.txt | sudo patch /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/universal-darwin13/rbconfig.rb
To address the issue you can install the most recent version of ruby as described by #Sash. You can use the following commands to do so. In case you already have installed rvm, you don't need to reinstall it.
#Install rvm
\curl -sSL https://get.rvm.io | bash -s stable
#Install ruby version 2.0.0-p451
rvm install ruby-2.0.0-p451
#Print ruby version to verify that it was installed successfully
ruby -v
#Install json gem
sudo gem install json
Issue already addressed by Ruby:
https://bugs.ruby-lang.org/issues/9624
now we just need to wait for Apple to update their ruby version (2.0.0p247) to the one after the latest one (2.0.0p451) which hasn't come out yet ...
(or brew/macport it)
Update (2014-05-15): Mavericks 10.9.3 updates ruby to
ruby 2.0.0p451 (2014-02-24 revision 45167) [universal.x86_64-darwin13]
And this seems to resolves the issue.
#Muncken has already provided an answer to install gem one by one:
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install GemName
Base on Muncken's answer, I've tried that it also works when using bundle install
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future bundle install
In my case, I actually have similar problem, but not on the system ruby, but on rubies installed by rvm from OSX 10.8, and it has issues after upgrading to OSX 10.9.
A simple reinstall works: rvm reinstall ruby-2.1.1
On OSX 10.10, I had several issues when running rails new firstapp such as:
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
fatal error: 'ruby/config.h' file not found
I updated rvm with this configuration and all the errors are gone!:
rvm get stable --auto-dotfiles
You can tell from the app name that I just started fiddling with Ruby on Rails, so the above advice may or may not work for you.
Paul Chechetin's one-liner doesn't appear to work anymore (9/21/15). However, this reply to the post mentioned in Pete's reply solved the problem for me:
(a) Install Apple's XCode, then (b) launch it and accept the licensing terms (I had done (a), but not (b).)
sudo gem uninstall compass
sudo gem install compass
None of these worked for me.
What finally worked is running the command with a sudo -
gem install byebug -v '9.0.6'
It's been a while and I've got similar error. An alternative to folks using bundler is to add the flag to the build configuration like below example:
bundle config build.<gemname> --with-cflags="-Wno-error=implicit-function-declaration"
followed by
bundle install
Please note that you must replace <gemname> above with the name of the actual gem that is throwing the error while building native extensions.
I hope this becomes helpful to others that face similar issues in the future!
I used a simple solution... install through brew
brew install name

Problem installing rspec-1.3.2 on Lion using RVM and ruby 1.8.6

I'm trying to install rspec version 1.3.2 on OS X Lion using RVM and Ruby 1.8.6
When I install, I get the following:
$ gem install rspec -v=1.3.2
Abort trap: 6
I'm able to successfully install the same rspec version using the system ruby. I've tried to do some research into the problem, but it doesn't look like anybody has run into the same thing. Similar questions have suggested export CC=gcc-4.2 before installing ruby. I tried that (after completely blowing away RVM and reinstalling the latest version, 1.6.31 right now) but it had no effect.
Has anyone else else encountered this? Have you found a solution?
I installed 1.8.6 fresh with no gems and installed with verbose flag...
gem install rspec -v=1.3.2 --verbose
GET http://rubygems.org/specs.4.8.gz
302 Moved Temporarily
GET http://production.s3.rubygems.org/specs.4.8.gz
200 OK
Installing gem rspec-1.3.2
Abort trap: 6
I see the problem of Abort Trap 6 seems to indicate that some dependency is missing. I was hoping that this would get resolved with the pristine command, but settled on just going down a version.
rvm gemset pristine
gem install rspec -v=1.3.1 --verbose
...
Successfully installed rspec-1.3.1
...
gem list
*** LOCAL GEMS ***
rake (0.9.2)
rspec (1.3.1)
Why must you use 1.3.2 instead of 1.3.1? Hope this helps.

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

Resources