rvm install rails on Mac OSX 10.7.3 - ruby-on-rails

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.

Related

Can't install Rails on MacOs. Error messages: Failed to build gem native extensions

When trying to install Rails from my terminal, on my Mac OS Big Sur, by typing "sudo gem install rails" I get the error message: "Failed to build native extension". I have ruby 2.6.3 installed. I tried installing Xcode as I saw that being suggested in forums, but it still doesn't work. I don't know what to do:
Here, the error in the terminal:
% sudo gem install rails
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/nio4r-2.5.8/ext/nio4r
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20211119-69718-1dr6qis.rb extconf.rb
checking for unistd.h... *** 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.
I have encountered a similar problem more than once.
I can think of three potential causes and solutions, though your problem may be rooted in something different.
1. Ruby version mismatch
You thought you were using Ruby 2.6.3. But actually the ruby your gem command recognises is a Ruby in a different version.
Check it out with ruby --version and make sure it is the right one.
If you have Rails in Ruby in a previous version, and if you have upgraded your Ruby since, then this type of error might be raised, depending on how your package management system handles the case.
If so, try uninstalling Rails first and reinstalling it.
2. Problem of installing Ruby
For some reason, the Ruby you are trying to use (2.6.3) has not been correctly installed. Then, a simple solution is to reinstall the Ruby, making sure it is correctly installed.
It highly depends which system you are using, but if you are using rbenv,
rbenv uninstall 2.6.3
rbenv install 2.6.3
rbenv rehash
should do the job. You can then reinstall your Rails.
3. Problem of permission (directory writing etc)
In your case, you run sudo gem install rails, and it probably means you have installed Ruby and Gems, including Rails, as the superuser while your Rails app directory is in a normal user.
I understand it is generally safer to install Ruby and Gems as the same user that runs Rails (mind you, though, it may not be impossible in practice in some specific environments). When the users are different, all sorts of permission problems can be encountered, and to install Rails apps are also problematic – it's possible but not straightforward in my experience.
So, my recommendation is, if ever possible and practical for you, to delete all the installed Ruby and reinstall it (=Ruby) as a normal user, who owns a Rails app directory, without using sudo. For example, if you are using rbenv, uninstall rbenv, delete all the directory related to rbenv, and reinstall rbenv from scratch as the normal user. Or, if you are using the system default Ruby, I'd recommend to install the Ruby-version management system, that is either rbenv or rvm, as the normal user, install Ruby(s) with it, and manage the installed Ruby versions with it.
If neither is possible or practical, check out the directory permission where Gems are installed and make sure they are consistent with what you would expect. Personally, I would make all the efforts to use a Ruby-version management system whenever I use Rails.

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.

Rails installation error - Failed to build gem native extension

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

ROR - Unable to create a new directory

(side note: my mac crashed a couple of weeks ago due to some os problem; the apple people at the store took care of it, and it's back to "normal" - just stating this in case it's related to the current problem)
today, i decided to practice some ruby after having not done it in a while (following hartl's tutorial)
when trying to generate a new application, after a pause and seemingly normal files, it comes up with this: (for the record - when I created my previous directories - I never had a problem with it until today)
Installing json (1.7.5) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/name_withheld/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
creating Makefile
make
sh: make: command not found
Gem files will remain installed in /Users/name_withheld/.rvm/gems/ruby-1.9.3-p0/gems/json-1.7.5 for inspection.
Results logged to /Users/name_withheld/.rvm/gems/ruby-1.9.3-p0/gems/json-1.7.5/ext/json/ext/generator /gem_make.out
An error occured while installing json (1.7.5), and Bundler cannot continue.
Make sure that `gem install json -v '1.7.5'` succeeds before bundling.
Tried to install json. This is what it comes up with:
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
/Users/name_withheld/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
creating Makefile
make
sh: make: command not found
Gem files will remain installed in /Users/name_withheld/.rvm/gems/ruby-1.9.3-p0/gems/json-1.7.5 for inspection.
Results logged to /Users/name_withheld/.rvm/gems/ruby-1.9.3-p0/gems/json-1.7.5/ext/json/ext/generator /gem_make.out
Anyway, it seems the problem may be related to gcc? or xcode?
I'm confused, and I never had a problem until today! Hence why I think it may be do something with the reset that the people at apple store may have done, maybe?
For the record, when I try to download command line for xcode which everyone says it's free, it's not. You have to register and pay some sort of licensing fee.
Help? Can anyone sort out my confusion on what I should do here?
Edit
Am on 10.6.8 version (ie Snow Leopard?)
Edit 2
Have added this to comments beneath, but also adding it here for further trouble-shooting if it helps.
This is what my path shows:
"/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/name_withheld/.rvm/bin"
You should also make sure you have Rails 3.x (ideally at least 3.2.y)... You can check which Rails you are running by doing:
$ rails -v
Use:
$ gem install rails
to get the latest version of Rails. Once you do a 'rails -v' and know you're running Rails 3, then a 'rails new foo' should create an app (and directory) called foo.
Also, Mischa had a typo, the command is:
$ gem update rails # *Not* gem rails update ...
I would also run the following to 'start over' with rvm:
$ rvm implode
Then reinstall rvm, per the instructions here.
You may also find this much easier: http://railsinstaller.org/#osx
Btw, homebrew and rvm are two totally separate things. brew is used to download, build (compile), and install packages using a local (on your Mac) compiler (gcc or CLI tools, put there via Xcode or the Kenneth Reitz gcc installer). rvm is Ruby Version Manager, it's only used to manage the different Ruby versions you might install. To use it, you just say 'rvm 1.9.3' (assuming you've installed Ruby 1.9.3 already) to make sure you're using that version of ruby.
Similar to Rails, you can check which version of Ruby you're using by doing:
$ ruby -v
Also, rvm will tell you which one you're using (if it says 'system' then try the 'rvm 1.9.3' or 'rvm 1.9.2' command to change the one you're using):
$ rvm list
The one in use will have a '=*' or '=>' next to the one you're using (if you have a fairly recent version of rvm installed).
Good luck--let me know if any of this helps.

Rubygems do not install on OS X Lion

I used to have no problems at all with ruby, gems and all related stuff. But after installing X Code Developer Tools and upgrading to Lion the gems do not install.
I get the following error for every gem. This is the message for sqlite as an example:
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
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/sqlite3-1.3.4 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/sqlite3-1.3.4/ext/sqlite3/gem_make.out
What went wrong? How to fix it?
I had to install the Command Line Tools in the latest Xcode-Version (4.3.1) and
sudo gem install rails
worked like a charm.
To install Command Line Tools, go to Xcode Preferences > Downloads or use the following command in terminal (thx #Purell):
xcode-select --install
I'm using Mavericks and Ruby 2.0.0 and I also got this error (mkmf.rb can't find header files) when installing gems. I solved this issue by creating some symbolic links in Terminal.
#First install developer tools again:
xcode-select --install
#Create symbolic link to Ruby include (updated for 10.9)
sudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/include
#Create symbolic link to config.h (updated for 10.9)
sudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/2.0/Headers/ruby/config.h /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/config.h
I faced same problem while trying to install rails on my Lion. This is how i could solve it.
Install rvm
$ curl https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable
Install osx-gcc-installer
https://github.com/kennethreitz/osx-gcc-installer
Installed new version of ruby
rvm install 1.9.3
Typed to following command to show the requirements
rvm requirements
To use an RVM installed Ruby as default, instead of the system ruby:
rvm system ; rvm gemset export system.gems ; rvm 1.9.3 ; rvm gemset import system.gems # migrate your gems
rvm alias create default 1.9.3
Installed rails:
sudo gem install rails
My Mac is now read for rails!! YAY!!
Not a direct solution to your problem, but I'd suggest using rvm to install fresh rubies and gems. That should take care of it.
While installing Rails I had the error :
can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
As i had already Xcode installed, I had just to install Command Line Tools to resolve this problem
You need to have XCode installed, it includes ruby.h as well as some other important files needed to compile other native gems.
Hello i'm sorry i can't test this answer but i would suggest to change the default search paths in your bashrc and extconf.rb since the Library files seem to be moved in Lion.
(P.S. if he wants to work with the default 1.8 Version, rvm would be an unneeded hassle)
Update to the latest version of xcode, that fixed the problem for me. Make sure xcodebuild is in your path.
running xcodebuild -version in a terminal window should output 4.2.1 (4.x at least).
After a OS-Update make sure that you do accept the X-Code license even when you have used command-line-tools before. Only then some header-files will be available. To accept the license you have to run X-Code once.
I just forgot to run it with the sudo command.
sudo gem install sqlite3
not:
gem install sqlite3

Resources