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
Related
I upgraded my OSX (Lion) to Mavericks and I can't install Nokogiri for my projects.
I already install XCode 5.0.1, Command Line Tools (using xcode-select --install), and already installed libxml2 from Homebrew and I am still having problems.
The error is:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/bin/ruby extconf.rb
checking for libxml/parser.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/bin/ruby
--with-zlib-dir
--without-zlib-dir
--with-zlib-include
--without-zlib-include=${zlib-dir}/include
--with-zlib-lib
--without-zlib-lib=${zlib-dir}/lib
--with-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-dir}/lib
--with-xml2-dir
--without-xml2-dir
--with-xml2-include
--without-xml2-include=${xml2-dir}/include
--with-xml2-lib
--without-xml2-lib=${xml2-dir}/lib
--with-xslt-dir
--without-xslt-dir
--with-xslt-include
--without-xslt-include=${xslt-dir}/include
--with-xslt-lib
--without-xslt-lib=${xslt-dir}/lib
--with-libxslt-config
--without-libxslt-config
--with-pkg-config
--without-pkg-config
--with-libxml-2.0-config
--without-libxml-2.0-config
--with-libiconv-config
--without-libiconv-config
/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:452:in `try_cpp'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:853:in `block in find_header'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:693:in `block in checking_for'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:280:in `block (2 levels) in postpone'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:280:in `block in postpone'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:254:in `open'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:276:in `postpone'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:692:in `checking_for'
from /Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/mkmf.rb:852:in `find_header'
from extconf.rb:116:in `<main>'
Gem files will remain installed in /Users/ericcamalionte/Locaweb/code/dns-panel/vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.9 for inspection.
Results logged to /Users/ericcamalionte/Locaweb/code/dns-panel/vendor/bundle/ruby/1.9.1/gems/nokogiri-1.5.9/ext/nokogiri/gem_make.out
An error occured while installing nokogiri (1.5.9), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.5.9'` succeeds before bundling.
I installed libxml2, libxslt and libiconv from Homebrew, and set the params to install Nokogiri, but don't work too.
I can't find what's wrong in my enviroment, can you help me?
You can also install Nokogiri on Mac OS X 10.9 Mavericks with full XCode Install using:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2
Update
For those using Yosemite the following command will work:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --use-system-libraries
or, it might actually be in your MacOSX10.11.sdk folder (mine was as of 18-Sep-2015) anyways, so even if you are not yet fully up to El Capitan, I had recently updated XCode and you may need to use the El Capitan SDK path, which follows next:
Update
For those using El Capitan the following command will work:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --use-system-libraries
Update
For those using Sierra the following command will work:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-libraries
After navigating the animated GIFs here, all that I had to do was simply xcode-select --install and the gem install nokogiri worked fine.
I found this log and saw that gcc-4.2 was not found:
package configuration for libxslt
cflags: -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2
ldflags: -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib
libs: -lxslt -lxml2 -lz -lpthread -liconv -lm -lxml2
package configuration for libxml-2.0
cflags: -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2
ldflags: -L/usr/local/Cellar/libxml2/2.9.1/lib
libs: -lxml2
package configuration for libiconv is not found
"/usr/bin/gcc-4.2 -o conftest -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/x86_64-darwin11.4.0 -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/ruby/backward -I/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1 -I. -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2 -I/usr/local/Cellar/libiconv/1.14/include -I/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/include -I/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/include -I/Users/ericcamalionte/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -fno-common -pipe -g -DXP_UNIX -O3 -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline -DNOKOGIRI_USE_PACKAGED_LIBRARIES -DNOKOGIRI_LIBXML2_PATH='"/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0"' -DNOKOGIRI_LIBXSLT_PATH='"/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26"' -I/usr/local/Cellar/libxslt/1.1.28/include -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2 -I/usr/local/Cellar/libxml2/2.9.1/include/libxml2 conftest.c -L. -L/Users/ericcamalionte/.rvm/rubies/ruby-1.9.2-p320/lib -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -L/usr/local/Cellar/libiconv/1.14/lib -L/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/lib -L/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/lib -L/Users/ericcamalionte/.rvm/usr/lib -L. -Wl,-rpath,/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxml2/2.8.0/lib -Wl,-rpath,/Users/ericcamalionte/.rvm/gems/ruby-1.9.2-p320#dns-panel/gems/nokogiri-1.6.0/ports/x86_64-apple-darwin13.0.0/libxslt/1.1.26/lib -L/usr/local/Cellar/libxslt/1.1.28/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -L/usr/local/Cellar/libxml2/2.9.1/lib -lxslt -lxml2 -lz -lpthread -liconv -lm -lxml2 -lxml2 -lruby.1.9.1-static -lpthread -ldl -lobjc "
sh: /usr/bin/gcc-4.2: No such file or directory
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */
To solve this problem I intalled apple-gcc42 using homebrew brew install apple-gcc42 and created a symlink to my /usr/bin :
sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 /usr/bin/gcc-4.2
If you're running Xcode 5.1, the command line tools don't work for nokogiri 1.6.1. You'll need to download the Late october 2013 tools from Apple. Once you do that run
sudo xcode-select -s /Library/Developer/CommandLineTools/
to set up your machine to use the Xcode 5.0.X command line tools, then run
gem install nokogiri
If you want to reset your command line tools to the Xcode.app version afterward run
sudo xcode-select -r
Or, another thing you can do is add the flag to ignore unknown command line arguments. Then the install looks like this:
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri
This is what worked for me on OSX Mavericks:
sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install nokogiri -v '1.6.1' --verbose --no-ri --no-rdoc
I'm on OSX Mavericks and my problem turned out to be a bad install of Ruby.
So, I reinstalled ruby with rvm :
rvm remove ruby 2.0.0p451
rvm remove ruby-2.0.0-p451 && rvm install ruby-2.0.0-p451
I was then able to
gem install nokogiri --no-ri --no-rdoc
Problem solved.
I like to stick with system-provided stuff typically. This worked for me:
gem install nokogiri -- --with-iconv-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/ --with-iconv-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/lib/
I ran into this problem immediately after installing the Mavericks 10.9.5 update and the 10.9 Developer tools update from Apple. I ran xcode-select --install, but that did not fix the problem. Then I opened XCode, accepted the eula, and quit XCode. That fixed the problem.
I had this problem today, on Maverick, this is how I ended up solving the issue:
brew update
brew install libiconv
brew link libiconv
Make sure that you know the version of libiconv in Cellar mine below was 1.14, then install as below:
gem install nokogiri -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14
If you require a particular version of nokogiri e.g -v '1.6.2.1' then install as:
gem install nokogiri -v '1.6.2.1' -- --with-iconv-dir=/usr/local/Cellar/libiconv/1.14
Nokogiri was installed successfully!
This is the same as #thomas_witt's post but works on Mac OS X Sierra:
gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/libxml2 --use-system-libraries
To get the install to work, I had to modify the filepaths in the gem install command to match those on my system. I have different versions of libxml2 and libiconv and a slightly different file structure. The command, with my modifications, is:
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2
--with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib
--with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28
--with-iconv-include=/usr/local/Cellar/libiconv/1.13.1/include
--with-iconv-lib=/usr/local/Cellar/libiconv/1.13.1/lib
For people using MacPorts, make sure you have installed libxml2 via MacPorts. Then type:
bundle config build.nokogiri --use-system-libraries
bundle install
This should do the trick, worked for me without using full paths.
Use brew install libxml2 libxslt if you use Homebrew.
Here is another reference:
system: OS X Yosemite 10.10
rvm: 1.26.10
brew: 0.9.5
ruby: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
I got error while installing nokogiri
error like this:
.rvm/rubies/ruby-2.2.0-p0/lib/ruby/1.9.1/mkmf.rb:368:in `try_do': The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
then probably need:
$ xcode-select --install
or if you got error like
checking for libxml/parser.h... no
I just fix the lib path by:
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 libxslt
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2/libxml --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
for bundle need something like:
bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.9.2/include/libxml2/libxml --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.2/lib --with-iconv-dir=/usr/local/Cellar/libiconv/1.14/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
bundle install
This works for me
system: OS X Yosemite 10.10
rvm: 1.26.10
ruby: ruby 2.2.1
Just run below two commands
$ xcode-select --install
It will ask you to download say "yes" then it will ask to install the xcode component click install.
Now try to install gem with below command
gem install nokogiri --no-ri --no-rdoc
This works for me with above environment.
I ran into the same issue for Mavrick, and the solution was:
xcode-select --install
However, that is not working as Apple's download page for Command-line-tool does not have that installer available publically now.
So, if you want to have the command-line tools for Mavricks you need to have a paid account. Then only you will be able to install it.
Once you install it you will not face this issue with Nokogiri.
I had this same error on a fresh Mavericks install. After having a lapse of judgement I renamed my Xcode app bundle to Xcode 5.0.1.app.
Apparently the Nokogiri installation script does not quote its paths and so the space in the file name caused all sorts or troubles. It wasn't until I tried brew install libxml2 that the error became obvious.
Lesson learned: spaces in file names are evil.
In my case, I had to actually run /usr/bin/gcc-4.2 after symlinking it. You have to accept the license agreement, otherwise it hangs.
The error message gives a clue here: The compiler failed to generate an executable file. (RuntimeError)
xcode-select --install # not sure if this is required
brew install apple-gcc42
gem install nokogiri
You also might need to brew install and link these:
libxml2 libxslt
brew install libxml2 libxslt
gem install nokogiri -- \
--with-xml2-include=/usr/local/Cellar/libxml2/*/include/libxml2 \
--with-xml2-lib=/usr/local/Cellar/libxml2/*/lib \
--with-xslt-dir=/usr/local/Cellar/libxslt/*
For me the error was that that gcc (4.2.1, installed from Homebrew) was complaining that:
-E, -S, -save-temps and -M options are not allowed with multiple -arch flags
I solved the issue by forcing x86_64 only:
ARCHFLAGS="-arch x86_64" gem install nokogiri
After upgrading to Maverick, I had a similar problem. I use RVM with Ruby 1.9.2-p320, and I tried several solutions given here, but nothing solved the problem.
Then I changed to Ruby 2.1.2, and bundle install installed Nokogiri immediately.
If anyone is having this issue on el capitan, whilst using bundler.
Make sure the xcode command line tools are installed and run this:
bundle config build.nokogiri --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/libxml2 --use-system-libraries
I was facing the same issue from past two weeks while trying to run a rails 3 version application.
The issue is that your rvm/rbenv is not using the C compiler.
Use this command for rvm to take compatible C compiler
CC=gcc rvm install-version
So if you are using Ruby 1.9.3, use it this way
CC=gcc rvm install-1.9.3
Use this command every time you are not able to bundle install or anything.
This thing is working on El Capitan, rails 3.2.16, ruby 1.9.3, mysql 5.7
Hopefully, It will resolve the issue.
I was facing the same issue from past two weeks while trying to run a rails 3 version application.
The issue is that your rvm/rbenv is not using the C compiler.
Use this command for rvm to take compatible C compiler
CC=gcc rvm install-version
So if you are using Ruby 1.9.3, use it this way
CC=gcc rvm install-1.9.3
Use this command every time you are not able to bundle install or anything.
This thing is working on El Capitan, rails 3.2.16, ruby 1.9.3, mysql 5.7
Hopefully, It will resolve the issue.
And also if you already have the Xcode and then also you are not getting the same errors installing any gem, try this solution.
I added my findings here after I came across this same issue shortly after an Upgrade: http://jasdeep.ca/2013/10/installing-nokogiri-fails-os-x-mavericks/
The fix simply is these 2 commands:
xcode-select --install
gem install nokogiri
Hope it helps.
I had this issue as well. Running brew doctor showed that I had an unexpected version of libiconv in /user/local/lib.
Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.
Unexpected dylibs:
/usr/local/lib/libcharset.1.dylib
/usr/local/lib/libiconv.2.dylib
So I removed them, and rebrewed libxml:
rm /usr/local/lib/libiconv*
andromeda:nokogiri-1.6.0 Jeff$ brew install libxml2 libxslt
...
==> Summary
🍺 /usr/local/Cellar/libxslt/1.1.28: 145 files, 3.3M, built in 36 seconds
Finally, I installed nokogiri:
Jeff$ gem install nokogiri
Building native extensions. This could take a while...
Successfully installed nokogiri-1.6.0
1 gem installed
None of these answers worked for my particular case, and since I am a newb I figured my solution might be able to help someone else.
I am using Yosemite and was using Ruby 1.9.3p547. There was a security exposure for p547 so I was trying to update to Ruby 1.9.3p550 or higher. I used RVM, then tried to migrate my gems and many of them didn't go. Then I tried to bundle install but that was failing and I thought maybe it was a conflict between the various paths and dependencies so I removed the older version of Ruby. This broke everything.
I kept getting a message saying that the C compiler was missing, even though I had downloaded XCode and recently updated the CLI tools. I found another website that told me to download a third party GCC, which I did. which made everything worse.
Now I'm getting a message saying I need to fix my profiles and PATHs or it might just be easier to reinstall OSX.
So I did.
Anyway, longer story merely long: the solution that finally worked for me was to get rid of RVM and just use brew to download the Ruby version I wanted then before running bundle install. Install the correct version of Nokogiri FIRST.
brew install ruby193
sudo gem install nokogiri -v '1.6.0'
bundle install
for windows you can also try local installation:
download the appropriate gem based on your environment.
go to the directory where you saved the gem file.
gem install --local nokogiri-1.6.3.1-x86-mingw32.gem
if not worked you may check if you have zlib and mingw or proper c compiler installed.
Every single darn thing on here didn't do it for me (I didn't get into brew reinstalls, oy), but this finally did (found via a bug report on some unrelated project):
gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2
Good luck. Yay for #yakshaving!
Check your Commandline tools version. Set up your machine to use the Xcode 5.0.X command line tools, then run:
gem install nokogiri
I'm attempting to install charlock_holmes on my Mac (10.7.5, ruby-1.9.3-p392), and I'm encountering the following error:
$gem install charlock_holmes -v '0.6.9.4'
Building native extensions.
This could take a while...
ERROR: Error installing charlock_holmes:
ERROR: Failed to build gem native extension.
/Users/mthompson/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
checking for main() in -licui18n... no
checking for main() in -licui18n... no
***************************************************************************************
*********** icu required (brew install icu4c or apt-get install libicu-dev) ***********
***************************************************************************************
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
I've installed icu via macports, so my icu directories are /opt/local/lib/icu and /opt/local/share/icu. I've tried installing with the directories specified:
$ gem install charlock_holmes -v '0.6.9.4' -- --with-icu-dir=/opt/local/lib/icu --with-opt-include=/usr/local/include/ --with-opt-lib=/usr/local/lib/
..but I hit the same error. Any ideas would be welcome.
I was able to install this gem using the version of ICU installed with macports and pointing --with-opt-include and --with-opt-lib to subdirectories of /opt.
The gem successfully installed by running:
gem install charlock_holmes -v '0.6.9.4' -- --with-icu-dir=/opt/local/lib/icu --with-opt-include=/opt/local/include/ --with-opt-lib=/opt/local/lib/
I ran into this issue today. I realize that the original issue was resolved by switching to Homebrew. That wasn't an acceptable solution to me, so I kept digging. The solution was actually quite simple.
After installing icu via Macports, simply install charlock_holmes by running:
gem install charlock_holmes -- --with-icu-dir=/opt/local
Hopefully this helps others that encounter this issue and are not willing to abandon Macports in order to solve it.
I ended up switching from MacPorts to Homebrew and reinstalling my rubies and packages.
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).
I have done all kinds of research and tried many different things. I know this question has been answered many times, but none of the suggested solutions are working for me.
After upgrading to Lion I am getting segmentation faults in Ruby. I'm fairly confident it's Nokogiri. So I installed libxml2 via Homebrew. I ran brew link libxml2. Then I reinstalled Nokogiri using that version of the library.
For proof:
$ nokogiri -v
# Nokogiri (1.5.0)
---
warnings: []
nokogiri: 1.5.0
ruby:
version: 1.9.2
platform: x86_64-darwin11.0.0
description: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0]
engine: ruby
libxml:
binding: extension
compiled: 2.7.8
loaded: 2.7.8
I've already included Nokogiri at the top of my gemfile and I've also required it in my environment file. I have no idea why I am still getting that warning.
Any suggestions or ideas to make sure it's loading the right version libxml2?
If you installed Nokogiri with gem install nokogiri, you can resolve this warning by running gem pristine nokogiri to recompile the gem's C extension.
If you installed Nokogiri with bundle install, you can resolve this warning by running bundle exec gem pristine nokogiri to recompile the C extension of the gem wherever Bundler installed it.
To fix this if you're using homebrew and bundler, add gem 'nokogiri' to the top of your Gemfile, then run these commands:
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 --with-xml2-config
brew install libxslt
bundle config build.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.26/
bundle install
If you don't use bundler, run these commands instead:
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 --with-xml2-config
brew install libxslt
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.26/
In your app, you should require nokogiri first, to force the app to load the dynamic libxml2 library instead of the older system version of libxml2 loaded by gems that failed to specify which library to load.
I just spent the better part of the morning working through this warning. This fix is for people using Mac OS Lion. The fix above using
bundle config build.nokogiri --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib --with-xslt-dir=/opt/local
is for Snow Leopard with libxml2 installed via MacPorts.
With Lion, libxml2 is loaded as part of the bootstrap process. Regardless of which libxml2 Nokogiri is pointing to, the Lion system default library for libxml2 will be used at runtime. Lion uses libxml2.2.7.3 found in /usr (not /usr/local).
As mentioned many other places, one can just ignore the warning. If, like me, the warning drives you crazy, you can do this:
bundle config build.nokogiri --with-xml2-dir=/usr --with-xslt-dir=/opt/local --with-iconv-dir=/opt/local
Interestingly, if you type nokogiri -v at the command line you will get the opposite warning:
WARNING: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.7.8
This suggests there is more to how libxml2 is being loaded, with Ruby and Rails using the system loaded libxml2 and the command line using libxml2 from the environment path. Anyway, this silences the error for me.
I’ll say it again – this is only for Lion. The previous fix will work for Snow Leopard.
This is the end of the answer. Stop reading here.
OK, you didn’t stop reading... well...
NOT RECOMMENDED!!!!!!
You have been warned. You can verify that Mac OSX is loading the libxml2 library in its bootstrap by disabling libxml2 found in /usr/lib. Do something like copying all versions of libxml2*.dylib to libxml2*.dylib.old (on my machine this was libxml2.2.7.3, libxml2.2 and libxml2).
After you have done this, running Nokogiri will not produce any errors. That is because it can’t find the loaded libxml2 and will now follow the environment path, eventually finding libxml2.2.7.8 in /opt/local.
BUT you won’t be able to copy the old libxml files back. This is because the OS needs the libxml2 that was loaded in the bootstrap.
Powering off and powering on again will brick your machine. The login screen will hang and hang and hang. Power off and power on again in single-user mode (hold Command-S while rebooting). You can watch the bootstrap occur. Low and behold, it throws an error that it can’t load libxml2 and then stops working.
Power off and power on again. This time boot into recovery mode (either hold Command-R or hold Option and then select the recovery disk). In recovery mode open the terminal (utilities/terminal). Mount /usr/lib on your HD (try /Volumes/Macintosh\ HD/usr/lib) and copy the libxml2 files back. Reboot and all will be fine.
None of this worked for me.
I had libxml2 installed at a later version (2.7.8) with brew. This caused nokogiri to compile against it and the later problems. Solution, remove it, then build, then install if desired.
Here's what worked:
brew uninstall libxml2 (if previously installed)
gem uninstall nokogiri
gem install nokogiri
brew install libxml2 (optional)
The solution (for me) after updating to Mountain Lion was much simplier:
gem uninstall nokogiri
# (and ignore the warnings about dependencies)
gem install nokogiri
As per the comment from patrickmcgraw above, simply putting nokogiri as the first entry in my Gemfile worked for me. I'm putting it as a separate answer because the original comment has been buried.
source 'http://rubygems.org'
gem 'nokogiri'
gem 'rails', '3.0.20'
etc...
Bundler has options to set the default build locations. So for instance, with libxml2 installed via macports:
$ bundle config build.nokogiri --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib --with-xslt-dir=/opt/local
After doing this and bundle install, the warning went away.
There's also some helpful examples for setting build options on the nokogiri wiki.
Looks like you have updated your system libraries after installing the gem, so you have to update Nokogiri. To use the current lib version:
gem install nokogiri -- --use-system-libraries
I had similar problem and just solved this way:
In my case, I have RVM installed, and I had #global and #project gem sets.
Both of them had nokogiri installed and one of them had built with with different libxml.
Rebuilding both of them (I have reason to do this) solved the problem.
Hope this helps..
gem uninstall nokogiri
bundle #install nokogiri again
If that fails with "libxml2 is missing." and you see gems/nokogiri-1.5.0/ext/nokogiri/mkmf.log trying to use "/usr/bin/gcc-4.2 ...", then you're missing /usr/bin/gcc-4.2
Solution:
sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
Before:
$ ll /usr/bin/gcc*
lrwxr-xr-x 1 root wheel 12 Jan 15 00:16 /usr/bin/gcc -> llvm-gcc-4.2
After:
$ ll /usr/bin/gcc*
lrwxr-xr-x 1 root wheel 12 Jan 15 00:16 /usr/bin/gcc -> llvm-gcc-4.2
lrwxr-xr-x 1 root wheel 12 Jan 15 21:07 /usr/bin/gcc-4.2 -> /usr/bin/gcc
If you're really missing libxml2 libxslt, then
brew update
brew install libxml2 libxslt
brew link libxml2 libxslt
bundle config build.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/
bundle
FYI: I'm running Mountain Lion with brew, and bundler.
gem install libxml-ruby helps me
I actually had 2 versions of libxml installed, one from source, one from an RPM.
The following is my complete solution
I uninstalled source (from the source directory)
sudo make uninstall
Remove bundles
rm -rf ~/.bundle ~/.bundler
Updated LD (might have to do this as root, not sudo)
sudo ldconfig
Then reinstalled the bundle
bundle install
Just ran into this myself (OS X Lion 10.7.5). My exact message was: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.7.3
I tried a few suggestions mentioned here, none worked, but this did:
gem install nokogiri -- --with-xml2-dir=/usr --with-xslt-dir=/opt/local --with-iconv-dir=/opt/local
The explanation is: "This happens because the Lion system default libxml2 (loaded at bootstrap) is used, regardless of which libxml2 Nokogiri was built against."
Credits to: https://coderwall.com/p/o5ewia
OS : Maverick 10.9.3
Ruby 1.9.3
WARNING: Nokogiri was built against LibXML version 2.9.1, but has dynamically loaded 2.9.0
My solution:
gem uninstall nokogiri
brew update
cd /usr/local
brew versions libxml2
git checkout 5dd45d7 /usr/local/Library/Formula/libxml2.rb # libxml version 2.9.0
brew install libxml2
bundle install or gem install nokogiri -v "1.5.11"
Hope this help
If you have this message and your nokogiri is out-of-date with the version available from the gem source, simply run bundle update nokogiri to get the new code and recompile. Your error should go away.
OS: Catalina
Warning: warning nokogiri was built against libxml version 2.9.10 but has dynamically loaded 2.9.4
I followed Michiel de Mare steps, but brew install libxml2 --with-xml2-config failed with invalid option error. So I installed libxml2 and libxslt and took note of the output from both commands.
brew install libxml2
==> Downloading https://homebrew.bintray.com/bottles/libxml2-2.9.10_2.catalina.bottle.tar.gz
Already downloaded: /Users/alberto/Library/Caches/Homebrew/downloads/9ddf5cb90fd16a7eb531e37bb748fd392f30214d9fe1568b2b70d28cc368c8f7--libxml2-2.9.10_2.catalina.bottle.tar.gz
==> Pouring libxml2-2.9.10_2.catalina.bottle.tar.gz
==> Caveats
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.
If you need to have libxml2 first in your PATH run:
echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.zshrc
For compilers to find libxml2 you may need to set:
export LDFLAGS="-L/usr/local/opt/libxml2/lib"
export CPPFLAGS="-I/usr/local/opt/libxml2/include"
For pkg-config to find libxml2 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig"
==> Summary
🍺 /usr/local/Cellar/libxml2/2.9.10_2: 280 files, 10.6MB
brew install libxslt
==> Downloading https://homebrew.bintray.com/bottles/libxslt-1.1.34.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/cbadecf3186f45754220dff4cbdfbb576882a211d615b52249a4c9d8ba4d7c3a?response-content-disposition=attachment%3Bfil
######################################################################## 100.0%
==> Pouring libxslt-1.1.34.catalina.bottle.tar.gz
==> Caveats
To allow the nokogiri gem to link against this libxslt run:
gem install nokogiri -- --with-xslt-dir=/usr/local/opt/libxslt
libxslt 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.
If you need to have libxslt first in your PATH run:
echo 'export PATH="/usr/local/opt/libxslt/bin:$PATH"' >> ~/.zshrc
For compilers to find libxslt you may need to set:
export LDFLAGS="-L/usr/local/opt/libxslt/lib"
export CPPFLAGS="-I/usr/local/opt/libxslt/include"
For pkg-config to find libxslt you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libxslt/lib/pkgconfig"
==> Summary
🍺 /usr/local/Cellar/libxslt/1.1.34: 136 files, 2.8MB
And I used those directories when configuring bundle for nokogiri
bundle config build.nokogiri --with-xml2-include=/usr/local/opt/libxml2/include --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xslt-dir=/usr/local/opt/libxslt
To summarize I executed these steps
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2
brew install libxslt
bundle config build.nokogiri --with-xml2-include=/usr/local/opt/libxml2/include --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xslt-dir=/usr/local/opt/libxslt
bundle install
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).