Rubygems do not install on OS X Lion - ruby-on-rails

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

Related

Uninstall Ruby, rbenv and homebrew and reinstall Ruby on Rails with RVM on MAC

I'm very new to RoR specially on Mac. I have installed it many times on Ubuntu with RVM and I'm very comfortable with that. Here is what happened on Mac:
I went through instructions as explained here http://goo.gl/zsHcCC then when I got to the point to install Rails with " gem install rails " I got this error:
Error installing rails:
ERROR: Failed to build gem native extension.
Now I want to roll-back everything and uninstall rbenv and it's ruby versions and reinstall the Ruby On Rails environment using RVM.
I tried to find how to uninstall Homebrew, RBENV and Ruby, but no success.
Thank you.
Sia
Homebrew or Rbenv are very good tools to have as a dev, I would think twice before removing either.
In this case I doubt they are at fault.
Can you confirm you have installed the GCC command line utils for OSX by running $ xcode-select --install in your terminal.
Here is a useful post explaining that process but I find that command generally works fine for me.
If this succeeds what does your $ gem install rails output next?
If you are very new you and you don't need specially the last version of Ruby. You can use Rails Installer http://railsinstaller.org/fr-FR.
To uninstall brew https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/FAQ.md

Error installing Rails on Mac OX Lion

I get this error when I try to install Rails on my Mac OS Lion. I used the command -
$ sudo gem install rails
/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
Any steps I need to follow to install rails?
Thanks
Just avoid using the bundled ruby, which is 1.8 and it is really outdated. Install rvm which will provide an up-to-date ruby version and then everything will work seamlessly. This is the only thing you need to start:
$ curl -L https://get.rvm.io | bash -s stable --rails
You will need the gcc/g++ toolchain (Xcode) to build everything but you would have needed it in anycase to compile any native gem.
It looks like you're missing some header files - try reinstalling XCode and the developer tools. If you already downloaded XCode, make sure you've run the installer that it put into /Applications for you.
Like Jack says, using rvm will be a lot smoother.
The system Ruby in Mac OS is outdated, I recommend to you install RVM or Rbenv to manage your installed Rubies or to install new versions.

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
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.
Im using osx 10.10. You can download from the command-line
xcode-select --install
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.
Did you install the OS X developer tools? You'll need to do this to be able to build native extensions
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
There are two possible reasons for the fail:
PRIMARY REASON: Missing Xcode Command Line Tools
Verifying Xcode Command Line Tools Installation manually:
Check for presence of
"/usr/include/iconv.h" (if absent=>Missing or improperly installed Xcode CLT)
Installing Xcode CLT:
Try running xcode-select --install on terminal and follow the instructions. If it fails, open Xcode.app, select from menu "Xcode" - "Open Developer Tool" - "More Developer Tools" to open the developer site, download the installer for your OS version and run it.
SECONDARY REASON(if 1. fails): Version issues
Try upgrading the ruby version using rbenv.
Hope it helps!
Steps to sort out this issue:
Follow these steps unless error is fixed.
Open terminal and run commands:
sudo xcode-select --install
sudo xcodebuild -license accept
Make sure you have installed only one Xcode and it is the latest one. If more than one version is installed then keep only the latest one with name in applications like Xcode.app
Open Xcode->preferences->locations then check if any command line tools are selected; if not then select
Install Ruby by:
brew install ruby
Install CocoaPods by
sudo gem install cocoapods
Try to install Ruby via RVM. I solved in this way
How to install ruby on Ubuntu with rvm
The Command line tools didn't solve this issue for me.
I upgraded ruby installation through rbenv to 2.2.0, made that the global default ruby installation, and this issue was fixed.
Switch Ruby to Homebrew version:
$ brew install ruby
$ brew link --overwrite ruby
$ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
$ echo 'export LDFLAGS="-L/usr/local/opt/ruby/lib"' >> ~/.bash_profile
$ echo 'export CPPFLAGS="-I/usr/local/opt/ruby/include"' >> ~/.bash_profile
Just had a similar issue. I can confirm that installing the command line tools fixes it.
https://stackoverflow.com/a/58226876/8070378
Solved after run:
sudo xcode-select --install
sudo xcodebuild -license accept
I had this problem on macOS Catalina 10.15.7, and it seems that Xcode 12.3's Ruby is a variant of 2.6, but my software needed 2.7.
I installed rvm and ran rvm install ruby-2.7, and now it works just fine 🎉

Installing Gems under RVM Error

I just purchased my first Mac, a 13" Air with Lion, and am coming from Linux. I'm installed RVM and my first Ruby (1.8.6), but I can't get a gem to install. Here's the input:
Ryan's Air :sudo gem install rails --version 2.0.2
Password:********
and the result:
/usr/local/rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/timeout.rb:59: [BUG] Bus Error
ruby 1.8.6 (2010-09-02) [i686-darwin11.2.0]
Ryan's Air :
Thanks in advance for any help on this.
Ryan
The issue is with Lion, and I've encountered this myself on now 2 brand-new 13-inch MBP's.
What you need to do is install the OSX GCC Compilers separately.
They can be found here: https://github.com/kennethreitz/osx-gcc-installer (scroll down to downloading pre-build binaries)
After downloading and running through the package installer (you should not need to install Homebrew), you need to find where the GCC folder is located. For some people, it was in /usr/bin; however, for me I found it in /Developer/usr/bin
Add this directory to your $PATH variable in your ~/.profile or ~/.bash_profile file. For me, I'm using ~/.bash_profile and added it to the end using vim.
Close your Terminal and open it again, and then echo $PATH to make sure the changes saved.
Completely uninstall that version of ruby, and install again normally:
rvm install 1.8.7
rvm use 1.8.7
If it still doesn't work, I recommend installing your version of rails using the following command as Hans specified in Why can't I install Rails on Lion using RVM?:
CC=/usr/bin/gcc-4.2 rvm install ruby-1.8.7 --force
the CC directory would change based on where your install was. However, after adding the correct path to gcc to my $PATH variable, I did not need to do the above command.
If you were still having this problem, hope this helps.
Look at this article. It seems that you get deadlocks with your combination of old rails, sqlite and Webrick. Michael is right, try to use modern version of rails.
rvm install 1.8.7-head
This worked for me, everything else failed. I did not install the gcc specifically, just clean Xcode 4.2

Why can't I install Rails on Lion using RVM?

I'm running into issues trying to install Rails on OS X Lion using RVM.
So far, I have done the following:
Installed Mac OS X Lion Version 10.7 (Build 11A459e).
Installed XCode 4.1 Developer Preview 5.
Installed RVM.
Installed a 1.8.7 version of Ruby via RVM using the command rvm install 1.8.7. Note: I need to be using 1.8.7 and not 1.9.2.
Switched to the 1.8.7 version of Ruby using the command rvm 1.8.7.
Created a new gemset using the command rvm gemset create rails3.
Switched to the new gemset using the command rvm use 1.8.7#rails3.
To install Rails I ran the command gem install rails but I got the following error:
/Users/m/.rvm/rubies/ruby-1.8.7-p334/lib/ruby/1.8/timeout.rb:60: [BUG] Segmentation fault
The same error happens when trying to run any gem command so I don't think it's really a problem with Rails.
Judging by the links below, I don't seem to be the only person having this issue:
http://twitter.com/#!/pingles/status/66261101351927809
and https://github.com/carlhuda/bundler/issues/1058
Fixed it!
The answer was actually on one of the links I posted above. Before installing a version of ruby (rvm install 1.8.7) I needed to run "export CC=/usr/bin/gcc-4.2". With that in place, everything ran smoothly.
If you don't want to have CC permanently exported, you can do CC=/usr/bin/gcc-4.2 rvm install 1.8.7
If you have already installed ruby 1.8.7. Just do CC=/usr/bin/gcc-4.2 rvm reinstall 1.8.7
If you have installed Xcode 4.2, it actually doesn't install non-LLVM gcc anymore, so you have to add it. For some reason downgrading to 4.1 after you've installed 4.2 doesn't work correctly (at least it didn't for me and others have had similar issues).
After quite a bit of thrashing, this is what finally worked for me:
Install Xcode 4.2 from App Store
Install darwin gcc using the OSX gcc installer
Install REE making sure you remove any vestiges of previous attempts:
Close any open terminal windows, open a fresh one and
rvm remove ree
export CC=/usr/bin/gcc-4.2
rvm install ree
This worked for me with rvm 1.8.6, OS X 10.7.2 and gcc-4.2 version 4.2.1 (Apple build 5666).
If you have already installed Xcode 4.1, resist the urge to upgrade to 4.2 and you should be okay.
If that still doesn't work add --force.
So this becomes:
CC=/usr/bin/gcc-4.2 rvm install ruby-1.8.7 --force
Make sure that you remove 1.8.7 if you already installed it before using "export CC=/usr/bin/gcc-4.2" by doing "rvm remove 1.8.7"
I had the same issue on my system. I installed the Xcode command line tools from Apple which ships with LLVM compiler and without an LLVM free one.
Ruby 1.8.7 won't work with an LLVM compiler not even with CC=clang, so installing an LLVM free gcc solves the problem.
There are multiple options listed here:
https://github.com/mxcl/homebrew/wiki/Custom-GCC-and-cross-compilers
Long story short, install GCC v4.2 with Homebrew:
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb
and then install ruby 1.8.7:
CC=gcc-4.2 rvm install 1.8.7
Instead of "export CC=/usr/bin/gcc-4.2" do "export CC=gcc" (xCode 4.2.x should be installed).
Check which version of gcc you have like this:
ls -Al `which gcc-4.2`
I followed the instructions here:
http://robots.thoughtbot.com/post/27985816073/the-hitchhikers-guide-to-riding-a-mountain-lion
brew update
brew tap homebrew/dupes
brew install apple-gcc42
Then reinstall:
Check again what your path to gcc is (to use for CC=):
ls -Al `which gcc-4.2`
(optional) You can set this in your .bashrc for example:
export CC=/usr/bin/gcc-4.2
(optional) remove any old version of ruby
rvm remove 1.8.7
Then:
CC=/usr/local/bin/gcc-4.2 rvm --verify-downloads 1 reinstall 1.8.7-p357 --without-tcl --without-tk
or if you have set CC in your profile
rvm --verify-downloads 1 reinstall 1.8.7-p357 --without-tcl --without-tk
Note the flags on the rvm install. I had trouble verifying the checksum on the ftp server and some problems with tck and what not. You may be able to omit those flags.
Also: you might need to remove an old version of your gemset:
rvm gemset delete <gemset>
Then
gem install bundler
bundle install
Hope this helps.
Using macport and ruby-1.9.x version.
I did successfully install rails with ruby gem.
I have same problem only for arch x86_64, when I comment line in my ~/.rvmrc
rvm_archflags="-arch x86_64"
Open a new terminal and tried to install ruby-1.8.7 again
rvm install 1.8.7
It was successful.
If you're using RVM in a development workflow, I added a fix in an .rvmrc file for OS X Lion.
https://gist.github.com/1112962
(updated file name)
This is not related to RVM, but if what you are looking for is a local development environment for Lion you may want to give a try to RubyStack It is a free, open source all-in-one installer for Apache, MySQL, Ruby, Rails, etc. It does not require compilation and it is self-contained so if you do not like it you can simply remove the installation directory and you are done. Disclaimer: I'm one of the RubyStack developers :)
CC=/usr/bin/gcc-4.2 rvm install 1.8.7 did not work for me, I used CC=/usr/bin/gcc rvm install 1.8.7 and it did (checking with "which gcc")
Even with all the other suggestions on this page I was still getting segfaults and getting frustrated, so I said "screw it!" and use the system-provided Ruby 1.8.7:
rvm use system
You need to use sudo for installing gems, but still waay less headache.
My solution was to override the /usr/bin/gcc symlink in the terminal. Here's how I did it:
https://plus.google.com/101970693023462019144/posts/eYVLvMCqTmc
This not only fixed my RVM installation, but also made sure that installing gems with native extensions (like rmagick) work.

Resources