Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 349
user884913 Avatar asked Dec 05 '11 17:12

user884913


4 Answers

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.

like image 156
Rob Avatar answered Oct 13 '22 23:10

Rob


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

xcode-select --install
like image 32
Abdullah Aden Avatar answered Oct 13 '22 23:10

Abdullah Aden


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.

like image 39
Alex Wayne Avatar answered Oct 13 '22 23:10

Alex Wayne


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

like image 5
RyanWilcox Avatar answered Oct 13 '22 23:10

RyanWilcox