Search code examples
ruby-on-railsrubyosx-elcapitan

Rails - ERROR: Error installing rails: ERROR: Failed to build gem native extension


My machine using OSX El Capitan. I already follow the instructions one by one. It's working fine until I need to install rails, something unwanted happened. BTW I already installed Xcode command line tools but still not fix even I restart the terminal and machine. I got this error message.

gem install rails -v 4.2.4

Error message

Last login: Sat Nov  7 15:07:53 on ttys000
Mohammads-MacBook-Air% gem install rails -v 4.2.4
Ignoring curb-0.8.8 because its extensions are not built.  Try: gem pristine curb --version 0.8.8
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

    /Users/ZERO/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20151107-786-tg78i0.rb extconf.rb
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using packaged libraries.
Ignoring curb-0.8.8 because its extensions are not built.  Try: gem pristine curb --version 0.8.8
-----
The file "/usr/include/iconv.h" is missing in your build environment,
which means you haven't installed Xcode Command Line Tools properly.

To install Command Line Tools, try running `xcode-select --install` on
terminal and follow the instructions.  If it fails, open Xcode.app,
select from the menu "Xcode" - "Open Developer Tool" - "More Developer
Tools" to open the developer site, download the installer for your OS
version and run it.
-----
*** 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=/Users/ZERO/.rvm/rubies/ruby-2.2.1/bin/$(RUBY_BASE_NAME)
    --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

extconf failed, exit code 1

Gem files will remain installed in /Users/ZERO/.rvm/gems/ruby-2.2.1/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /Users/ZERO/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-14/2.2.0-static/nokogiri-1.6.6.2/gem_make.out
Mohammads-MacBook-Air% 

Reference: https://gorails.com/setup/osx/10.11-el-capitan


Solution

  • It's working now. Using rvm to handel it.

    rvm install ruby-2.1.1
    rvm 2.1.1
    gem install rails -v 4.1.0