110

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?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
squiter
  • 5,711
  • 4
  • 24
  • 24
  • possible duplicate of [Error installing nokogiri 1.6.0 on mac (libxml2)](http://stackoverflow.com/questions/17863477/error-installing-nokogiri-1-6-0-on-mac-libxml2) – davidcondrey Feb 10 '15 at 03:10
  • 2
    Try opening xcode and accept the EULA/license. – moander Jun 13 '15 at 12:35

30 Answers30

243

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
Jean
  • 825
  • 8
  • 17
Thomas Witt
  • 2,559
  • 2
  • 12
  • 5
  • 4
    Not for me: "libxml2 is missing. please visit http://nokogiri.org/tutorials/installing_nokogiri.html for help with installing dependencies." Still getting same error. – Pop-A-Stash May 06 '14 at 16:58
  • 1
    Had to add --use-system-libraries. Than it worked on a brand new mavericks installation with Xcode 5.1.1 and brew. – jmg Aug 24 '14 at 15:12
  • 11
    Had to add the `--use-system-libraries` to get this to work: `gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 --use-system-libraries` – Maverick Sep 05 '14 at 22:30
  • With bundler, I used `bundle config build.nokogiri --with-iconv-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr` – Brian Hempel Sep 28 '14 at 23:09
  • This worked for me: `gem install nokogiri -- --use-system-libraries` – Tod Birdsall Dec 08 '14 at 20:04
  • This worked for me, i tried about 50 SO threads and this was the only one that worked... osx 10.10.3 – Josh May 05 '15 at 04:36
  • 1
    This is the only one that would work for me, on 10.10.3: sudo gem install nokogiri -- --with-iconv-lib=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib --with-iconv-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2 --use-system-libraries – Erik Villegas May 18 '15 at 20:37
  • This post being updated for El Capitan makes me happy. – Arian Faurtosh Oct 28 '15 at 19:36
  • 10
    You may want to update your answer with the more generic command that should work across all OS X versions and Xcode install paths: `gem install nokogiri -- --with-xml2-include=\`xcrun --show-sdk-path\`/usr/include/libxml2 --use-system-libraries` – Philipp Nov 26 '15 at 17:02
  • The command for El Capitan worked for me as well to install -v '1.6.6.2'. Thank you! – Dex Dec 11 '15 at 14:03
30

After navigating the animated GIFs here, all that I had to do was simply xcode-select --install and the gem install nokogiri worked fine.

Micah Alcorn
  • 2,363
  • 2
  • 22
  • 45
20

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

squiter
  • 5,711
  • 4
  • 24
  • 24
15

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
Alpine
  • 1,347
  • 12
  • 13
12

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
ReneGAED
  • 2,246
  • 2
  • 15
  • 11
  • amazingly this is the only thing in this entire tread that helped me too. thanks! – KonstantinK Nov 17 '14 at 22:16
  • The problem with this is, using `sudo` with RVM or rbenv will cause problems as root doesn't know where the sandboxed Rubies live. This is covered in [the RVM installation page](http://rvm.io/rvm/install). The OP is using RVM, and using `sudo` would cause Nokogiri to install into Apple's Ruby, not the user's. So, don't do this unless you are *SURE* you want to install into Apple's Ruby if you're on Mac OS, or into the system Ruby if you're on another *nix. – the Tin Man Dec 29 '14 at 19:39
10

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.

sulfurious
  • 101
  • 1
  • 4
  • Cool. Now that you are using rvm on mavericks try opening vim. SEGV error? Lovely. – Tim Sep 24 '14 at 08:55
  • I couldn't remove the gemset because the folders weren't empty, but reinstalling the gemset (even though there were errors) did! This is the only thing that worked for me! – Onikoroshi Dec 15 '16 at 22:11
9

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/
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
King Spook
  • 381
  • 4
  • 10
5

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.

ConcurrentHashMap
  • 4,998
  • 7
  • 44
  • 53
philosodad
  • 1,808
  • 14
  • 24
3

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!

Kingsley Ijomah
  • 3,273
  • 33
  • 25
3

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
edwardmp
  • 6,339
  • 5
  • 50
  • 77
2

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
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
darkmoves
  • 328
  • 3
  • 12
  • I had to be very meticulous with the filepaths. It took me multiple tries to correctly construct the commands. – darkmoves Nov 26 '13 at 13:52
  • Here's a [link](https://coderwall.com/p/efp3xg) to another solution to the issue of an incorrect libxml version. – darkmoves Jan 25 '14 at 21:39
2

Use brew install libxml2 libxslt if you use Homebrew.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
ryancheung
  • 2,999
  • 3
  • 24
  • 25
2

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.

patm
  • 1,420
  • 14
  • 19
2

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
ken
  • 787
  • 8
  • 14
2

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.

Rameshwar Vyevhare
  • 2,699
  • 2
  • 28
  • 34
1

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Dave Teare
  • 509
  • 3
  • 7
1

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
shinesecret
  • 1,402
  • 12
  • 16
  • I don't have a paid account and I was installed the command-line tools. I installed using terminal, but a friend of mine installed using that download page, and he doesn't have a paid account too. – squiter Nov 26 '13 at 14:16
  • I Agree with you. Same thing happened with me till 24th Nov, 2013. However if you go to that page now and try to access it, it will give you this error. Weird thing is you login with your credentials but it will keep you login as guest. This is the message I get on page with my account: Apple Developer Program Big Warning We are unable to process your request. Please go back to the previous page, or quit your browser and try your request again. If you require assistance, please contact Apple Developer Support. – shinesecret Nov 27 '13 at 07:28
1

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.

mcartmell
  • 236
  • 3
  • 5
1

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.

Jasdeep Singh
  • 3,276
  • 4
  • 28
  • 47
  • 5
    Please post the stuff here - links are liable to be broken (see the guidelines) – Justin Dec 11 '13 at 19:05
  • It helped me, although I do echo the sentiment of posting the answer here, rather than in a link :) – Richard Jun 20 '14 at 11:20
  • This is what is considered a Link-only answer which are discouraged on Stack Overflow. Instead of only posting a link to your own site, also summarize the important information in your answer. That way, if the link rots, like they tend to do, the answer will continue to provide some value. – the Tin Man Jan 01 '15 at 14:32
1

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
Rimian
  • 36,864
  • 16
  • 117
  • 117
1
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/*
Slava V
  • 16,686
  • 14
  • 60
  • 63
1

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.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Paul Verschoor
  • 1,479
  • 1
  • 14
  • 27
1

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 
Tor Arne
  • 721
  • 6
  • 11
1

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
gibo
  • 527
  • 2
  • 5
  • 22
1

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.

0

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
Jeff Paquette
  • 7,089
  • 2
  • 31
  • 40
  • i had a similar issue (an unlinked libiconv). I unlinked libiconv, and reinstalled. brew install libiconv, then gem install nokogirl. – Ben Oct 29 '14 at 10:56
0

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
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Gabriel Pumple
  • 783
  • 5
  • 16
  • Using `sudo` will cause Nokogiri to be installed in the only Ruby known by root, which is highly likely to be Apple's installed Ruby *unless* using Homebrew. Because the OP was using RVM, that means Nokogiri wouldn't be seen by a RVM managed Ruby, and would only compound the problem. Using `sudo` might have worked in this case, but it should not be tried with a RVM or rbenv managed Ruby. RVM specifically says not to do it in [the installation documentation](https://rvm.io/rvm/install#1-download-and-run-the-rvm-installation-script). – the Tin Man Dec 29 '14 at 19:42
0

for windows you can also try local installation:

  1. download the appropriate gem based on your environment.

  2. go to the directory where you saved the gem file.

  3. 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.

DragonKnight
  • 1,740
  • 2
  • 22
  • 35
0

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!

Dan Ancona
  • 162
  • 7
-3

Check your Commandline tools version. Set up your machine to use the Xcode 5.0.X command line tools, then run:

gem install nokogiri
the Tin Man
  • 158,662
  • 42
  • 215
  • 303