I was trying to get knife ec2 working on my Mac, but even though my system Ruby was at 2.0.0, the embedded Ruby that chef/knife use (in /opt/chef/embedded/bin) was 1.9.1. Installing knife-ec2 should just be a matter of typing “gem install knife-ec2” but due to some weird issues with nokogiri, I burned about 4 hours trying to make it work. I tried everything I could find – installing iconv, libxml2, and libxslt via brew and telling “gem install” to use the custom libs in /usr/local/Cellar was the most common suggestion on StackOverflow – but nothing worked. What ended up fixing it for me was reinstalling chef. 😐
[evan@Evan ~] $ sudo /opt/chef/embedded/bin/gem install nokogiri Building native extensions. This could take a while... Building nokogiri using packaged libraries. ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. /opt/chef/embedded/bin/ruby extconf.rb Building nokogiri using packaged libraries. checking for iconv.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=/opt/chef/embedded/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 /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp' from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:931:in `block in have_header' from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for' from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone' from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:254:in `open' from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone' from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:254:in `open' from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:280:in `postpone' from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for' from /opt/chef/embedded/lib/ruby/1.9.1/mkmf.rb:930:in `have_header' from extconf.rb:103:in `have_iconv?' from extconf.rb:148:in `block (2 levels) in iconv_prefix' from extconf.rb:90:in `preserving_globals' from extconf.rb:143:in `block in iconv_prefix' from extconf.rb:116:in `block in each_iconv_idir' from extconf.rb:113:in `each' from extconf.rb:113:in `each_iconv_idir' from extconf.rb:137:in `iconv_prefix' from extconf.rb:428:in `block in ' from extconf.rb:161:in `block in process_recipe' from extconf.rb:154:in `tap' from extconf.rb:154:in `process_recipe' from extconf.rb:423:in `' Gem files will remain installed in /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.3.1 for inspection. Results logged to /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.3.1/ext/nokogiri/gem_make.out [evan@Evan ~] $
Well, this is apparently an indication that you don’t have the command-line dev tools installed on your computer. However, in Mavericks, according to Apple:
If Xcode is installed on your machine, then there is no need to install them. Xcode comes bundled with all your command-line tools. OS X 10.9 includes shims or wrapper executables. These shims, installed in /usr/bin, can map any tool included in /usr/bin to the corresponding one inside Xcode. xcrun is one of such shims, which allows you to find or run any tool inside Xcode from the command line. Use it to invoke any tool within Xcode from the command line.
wat?
I spent several hours trawling through StackExchange, Googling for every combination of nokogiri, mavericks, chef, xcode. Here are some of my searches from today:
- https://www.google.com/search?q=%22You+have+to+install+development+tools+first.%22&hl=en
- https://www.google.com/search?q=osx+mavericks+command+line+tools&hl=en
- https://www.google.com/search?q=%22The+compiler+failed+to+generate+an+executable+file.%22+%22You+have+to+install+development+tools+first.%22+nokogiri&hl=en
- https://www.google.com/search?q=mavericks+nokogiri+%22iconv.h%22&hl=en
- https://www.google.com/search?q=chef+embedded+nokogiri+iconv&hl=en
- https://www.google.com/search?q=mavericks+nokogiri+%22iconv.h%22+chef+embedded&hl=en
- https://www.google.com/search?q=nokogiri+%22The+compiler+failed+to+generate+an+executable+file.+(RuntimeError)%22&hl=en
How did I end up fixing it? Two things:
- In ~/.bashrc, add export PATH=/opt/chef/embedded/bin:$PATH
- Reinstall chef: curl -L https://www.getchef.com/chef/install.sh | sudo bash
After reinstalling chef (which installed an embedded Ruby 1.9.3 – my old version was 1.9.1), this command ran successfully:
$ sudo gem install -V --no-rdoc --no-ri nokogiri
Full output below:
Continue reading ““You have to install development tools first.” – OSX Mavericks, ruby, chef, and nokogiri”