Rails installation error - Failed to build gem native extension - ruby-on-rails

I seem to have a conflict when trying to install Rails on Mountain Lion. I have tried updating Ruby but this did not help. I also tried Rails Installer but that also gave an error. Ruby version is 1.8.7
Here is the error I am getting from terminal
sudo gem install rails
Building native extensions. This could take a while...
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/atomic-1.1.10 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/atomic-1.1.10/ext/gem_make.out

I was having the same issues and I had all the requirements. My solution? Upgraded (through RVM) my version of Ruby from 2.0.0-p195 to 2.0.0-p353. After this I tried gem install rails and it worked like it was supposed to.

I installed the x-code command line tools and then the rails install worked correctly.

Use RailsInstaller and these step-by-step instructions:

I found the answer here, http://net.tutsplus.com/tutorials/ruby/how-to-install-ruby-on-a-mac/
Although by no means was this a walk in the park, due to version conflicts, the tut is over a year old and Rails now requires at least Ruby 1.9.3 and you need to install Command Line tools in Xcode. This tut uses RVM.
I tried Rails Installer which sounds a lot easier than doing it this way but that also gave me an error. I think I had major version conflicts going on. If you are trying to install Rails then I'd try Rails Installer first. Here's a very recent tut on installing it, http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-mac

Related

Rails install ERROR: Failed to build gem native extension

I am trying to install rails on my mac, but every time I type sudo gem install rails into the command line, I get the following error message. I have been stuck for a while, hope you can help.
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/include/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/atomic-1.1.14 for inspection
Results logged to /Library/Ruby/Gems/2.0.0/gems/atomic-1.1.14/ext/gem_make.out
If you are trying to install Rails 4.0, it needs RubyGems 2.0.3, so you have to update your system by using following command
gem update --system 2.0.3
and then continue with your installation.
Hope it helped
I would just use rvm. It should work like a charm. Or you could dig around and see if you can find that ruby.h file its talking about. But I personally think the latter would be a pain in the ass.
Upgrade xcode by typing following command in terminal window-
xcode-select --install
This should solve your isssu.
yea the rvm works like a charm and it will come in handy when you want to switch between different rails versions
I had the same issues. I upgraded my version (using RVM) of Ruby from 2.0.0-p195 to 2.0.0-p353 (make sure you tell RVM to use the new version as the default). After this I did gem install rails again and it worked fine.
Make sure you have installed the right version of DevKit, you can get it from here...
http://rubyinstaller.org/downloads/
and install as it says here:
https://github.com/oneclick/rubyinstaller/wiki/Development-Kit#installation-instructions
if you still have the problem even after Upgrading Xcode.
Its may be because :
The Apple LLVM compiler in Xcode 5.1 treats unrecognized command-line options as errors. This issue has been seen when building both Python native extensions and Ruby Gems, where some invalid compiler options are currently specified.
To workaround this issue, set the ARCHFLAGS environment variable to downgrade the error to a warning.
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install GemName
Personally I have got this problem while installing json gem , I did :
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install json
And the problem was solved.

Macbook Pro Rails Installation Error

I recently bought a macbook pro and downloaded the Mac OS mountain lion. I was told that ruby was already pre installed and that to download rails, I would type:
$ sudo gem install rails
However, when I do this, I get this error:
Building native extensions. This could take a while...
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.7.5 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/json-1.7.5/ext/json/ext/generator/gem_make.out
I have looked around stackoverflow for answers and tried downloading Xcode version 4.4.1, except $ sudo gem install rails still doesn't work. Also, when I try the command without sudo, it tells me:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /Library/Ruby/Gems/1.8 directory.
Is there a solution to fixing this problem? Other people have mentioned something called rvm, except I don't really know what that is or how to use it.
Had a similar problem on same system as above. Xcode doesn't include the command line tools pre installed. To install these, go to preferences -> downloads section and select components, then download command line tools. This may or may not solved the above problem.
RVM allows you to switch between Ruby versions. You may not want to develop RoR apps with the default Ruby on Mountain Lion, and rather than replacing the system installed ruby, RVM allows you to use other (ie later) Ruby versions without impacting your base installed Ruby that comes with OS X.
I have previously used this as a guide when setting up Ruby On Rails under OS X:
http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-mac

rvm install rails on Mac OSX 10.7.3

was hoping someone could point me in the right direction as I am unable to find a previously posted answer to my question of trying to install rails on my mac mini running Lion OSX 10.7.3. I have ruby version 1.8.7 and rvm 1.12.5 but when I come to install rails using sudo gem install rails I get the following:
Building native extensions. This could take a while...
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.7.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/json-1.7.0/ext/json/ext/parser/gem_make.out
The content of gem_make.out are:
/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
which did not really help me so not sure what it is I am missing? Any help or directions to help me solve this problem would be appreciated. Many thanks.
rvm is not intended to be used with sudo except during a multi-user installation - try simply gem install rails. Even better, rvm now has a guided rails install,
curl -L get.rvm.io | bash -s stable --rails
Take a look at RVM installation page for more details. If you're still having trouble, post the commands you're trying. The #rvm channel on irc.freenode.net is very helpful too.
In order to build Ruby and many other gems you'll need a working compiler. Unfortunately Apple has made this quite complex so there's a command in rvm to help: rvm requirements
you should not use sudo gem ... it basically looses your environment settings and prevents you from using RVM.
Please follow #tantrix instructions.
Sounds like you'll need to install XCode on your machine to get the necessary header files for building the Rails gem. It's a huge installation, unfortunately.
There was, at one point, a way to load (e.g.) the stuff on your machine that you need to build Rails without installing XCode, but I can't seem to locate it at the moment.
In my case,
I run rvm requirements and it helps me install gcc.
But the problem still exists and only solved after I restarted osx.

Error installing Rails

I know other people have asked this but the suggested fixes don't seem to work for me. I'm trying to install Rails v. 3.2.3 on a Mac OS X Lion, using Ruby 1.8.7. In terminal:
$ sudo gem install rails -v 3.2.3
And then I get the error message:
Building native extensions. This could take a while...
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.7.0 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/json-1.7.0/ext/json/ext/parser/gem_make.out
I've seen some people suggest installing Xcode v. 4.3.2, which I have, but I'm not sure if I need to do something special with Xcode to get the Rails installation to work. Any help is appreciated.
The easiest install way is by using RVM
here is a pretty good guide:
http://thinkvitamin.com/code/ruby-on-rails/installing-ruby-rails-and-mysql-on-os-x-lion/

Installing rails issue

I'm trying to use Rails, when I do this system says the following
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
Then I run - sudo gem install rails
and as the result I got
Building native extensions. This could take a while...
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.5 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/json-1.6.5/ext/json/ext/parser/gem_make.out
Any ideas how to solve this?
You're a Mac user. The 'common build tools', known as the 'BSD subsytem' in the Xcode package are often outdated. For example the installed ruby is at version 1.8. Do yourself a huge favor and install the common build tools via homebrew package manager. After that I suggest installing a newer version of ruby as rails will soon drop support for the 1.8 series that you're using. Different version of ruby are installed using the ruby version manager
After installing homebrew and rvm you have rock solid base! Installing a ruby version is now just a matter of running rvm install 1.9.2 and you'll get the latest patch version of the 1.9.2 series of the MRI.
With ruby 1.9.2 you will have no problem installing the current version of RubyOnRails.
This chain if tools is what most Ruby/Rails devs use today.
he got problems with installing the json gem. I resolved that issue by installing the Ruby DevKit.
Download form here:
http://rubyinstaller.org/downloads/
Install tutorial here:
https://github.com/oneclick/rubyinstaller/wiki/Development-kit
Cheers Stefan

Resources