macOS, Rails: "Failed to build gem native extension"
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
Admin
Updated on July 09, 2022Comments
-
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
andsudo 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 over 12 yearsthat worked - thanks very much. Brand new to developing on mac so apologies if this question was rudimentary
-
Mathieu Le Tiec over 11 yearsThanks Rob! That was the missing piece of the puzzle!
-
connorbode about 10 yearsI 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 over 8 yearsThis was the correct answer for me. Tried the one above and I didn't see the CLI tools in the list.
-
walter almost 8 yearsThis works for mesmo with Mac OS X 10.11.5 - El Capitan
-
Alessandro Francucci about 3 yearsIn 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 over 2 yearsMight want to close and reopen the terminal before running sudo gem install cocoapods