macOS, Rails: "Failed to build gem native extension"

66,696

Solution 1

If you have XCode 4 or later you will need to open it and go to Preferences -> Downloads -> Components and install the Command Line tools as they aren't installed by default. Couldn't install Rails until this happened.

Solution 2

Im using osx 10.10. You can download from the command-line

xcode-select --install

Solution 3

Not sure what it needs to compile, but OSX can't compile any native ruby extensions at all unless the Apple developer tools are installed. On 10.7 Lion you can download it free from the app store, or Download it here for 10.6: http://developer.apple.com/xcode/index.php

It may also be on your OSX install discs, though probably much more out of date.

Solution 4

Just a follow up ...

it may be that you are on a mac and rails cannot find the right compiler for c headers.

just install xcode from apps store / homebrew or go to terminal ...

$ xcode-select --install

complete the installation and agree on the licensing etc, then ...

$ sudo gem install rails

Solution 5

Did you install the OS X developer tools? You'll need to do this to be able to build native extensions

Share:
66,696
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm stuck trying to install rails on my mac. I have OS X 10.6.8 and I have confirmed that I have Ruby, version 1.8.7

    I ran sudo gem update and sudo gem update --system to get the latest versions of the software.

    However, when I run sudo gem install rails I get this error:

    ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.
    
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
    mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
    
    
    Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/json-1.6.3 for inspection.
    Results logged to /Library/Ruby/Gems/1.8/gems/json-1.6.3/ext/json/ext/parser/gem_make.out
    
  • Admin
    Admin over 12 years
    that worked - thanks very much. Brand new to developing on mac so apologies if this question was rudimentary
  • Mathieu Le Tiec
    Mathieu Le Tiec over 11 years
    Thanks Rob! That was the missing piece of the puzzle!
  • connorbode
    connorbode about 10 years
    I did need to install command line tools, but this solution did not work for me (Command Line tools wasn't listed in components). This alternate solution worked for me
  • Theo
    Theo over 8 years
    This was the correct answer for me. Tried the one above and I didn't see the CLI tools in the list.
  • walter
    walter almost 8 years
    This works for mesmo with Mac OS X 10.11.5 - El Capitan
  • Alessandro Francucci
    Alessandro Francucci about 3 years
    In my case, the point #2 was the problem since by default I can't work with the latest Xcode. I was going nuts! PS: In my cases, also a software update will be needed. Thanks for sharing!
  • T M
    T M over 2 years
    Might want to close and reopen the terminal before running sudo gem install cocoapods