83

I'm running into issues trying to install Rails on OS X Lion using RVM.

So far, I have done the following:

  1. Installed Mac OS X Lion Version 10.7 (Build 11A459e).
  2. Installed XCode 4.1 Developer Preview 5.
  3. Installed RVM.
  4. 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.
  5. Switched to the 1.8.7 version of Ruby using the command rvm 1.8.7.
  6. Created a new gemset using the command rvm gemset create rails3.
  7. Switched to the new gemset using the command rvm use 1.8.7@rails3.
  8. 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

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Michael Jerome
  • 1,601
  • 1
  • 12
  • 6
  • 2
    You are walking a very-bleeding edge, and the addition of 1.8.7 probably complicates matters. I'd recommend trying to install 1.9.2, then Rails and see how that goes. THEN I'd try retrofitting 1.8.7 and Rails. As is, you are using two pieces of software that are not released yet, so you'll find support might not be caught up yet. The "segmentation fault" is often the result of a 32-bit build against a 64-bit system, which could happen with unexpected system versions. Study the output of `rvm info` and see what it says. It might hold some clues. – the Tin Man May 30 '11 at 00:23
  • 2
    Just as fair warning, Lion is under NDA, so you're probably not allowed to talk about this outside of the designated Apple channels. Apple could revoke your developer account for discussing it if they were so inclined. – Chuck May 30 '11 at 04:39
  • Thanks @the Tin Man: I'll see if there's anything in rvm info. Sadly, I **have** to use 1.8.7 for this project; following the above steps but with Ruby 1.9.2 allowed Rails 3 to install just fine. – Michael Jerome May 30 '11 at 11:24
  • Thanks for the warning @Chuck - I'll be careful not to disclose anything I have agreed not to. – Michael Jerome May 30 '11 at 11:25
  • RVM 1.9.2 does not work with any of these suggestions. rvm detects llvm and won't run – Dale Nov 25 '11 at 15:02
  • Run `rvm get head` to update to a more recent RVM. – the Tin Man Jan 23 '12 at 16:07

14 Answers14

77

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

Henrique Gontijo
  • 1,052
  • 2
  • 15
  • 27
Michael Jerome
  • 1,601
  • 1
  • 12
  • 6
  • I remember reading somewhere that llvm would be default compiler on lion, I suppose this is why you require something like that. – Schmurfy Jun 18 '11 at 18:21
  • 3
    Using that export command changes CC for all subsequent commands in your session... which could mess up other compilations. Use `CC=/usr/bin/gcc-4.2 rvm install 1.8.7` all one one line to just override CC for the rvm install. – skue Jul 03 '11 at 01:34
  • For what it's worth, @skue's note didn't work for me. I had to add this in my `.zshrc` file. – Ben Kreeger Jul 20 '11 at 14:19
  • 1
    @Benjamin You are using Z Shell, correct? Worth noting, because obviously most Mac users just use Terminal + Bash. – Alan H. Jul 20 '11 at 16:32
  • 1
    @Alan H. -- yes, definitely zsh. FWIW, in Lion, I had trouble with zsh firing `.rvmrc` scripts, so I've switched back to `bash` for a while. Thus, I've added that line to my `.bash_profile`. – Ben Kreeger Jul 20 '11 at 18:52
  • @Schmurfy llvm (llvm-gcc/clang) applise different optimization approach than GCC (or broken optimization). Whether LLVM or/and Ruby is/are wrong, it breaks Ruby 1.8.7 (and 1.9.2). – naruse Jul 26 '11 at 07:17
  • Bummer, I still get: `checking whether the C compiler works... no` – turboladen Dec 03 '11 at 19:32
  • @MichaelJerome, if that is the correct answer, then select it as accepted so the question will be flagged as accepted by the system. Good job. – the Tin Man Jan 23 '12 at 16:00
24

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:

  1. Install Xcode 4.2 from App Store
  2. Install darwin gcc using the OSX gcc installer
  3. 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.

Matt Sanders
  • 8,023
  • 3
  • 37
  • 49
  • Didn't see this previous time I came around, but found this package in another tutorial.. But a great answer if the above recommendations don't work!! – Tim Baas Nov 03 '11 at 15:50
  • Yeah, I just got a new MBP and none of the previous answers worked for me. FWIW, when I installed Xcode, I, of course, got the latest version, which is 4.2.1 right now. I installed the OSC gcc installer, added the export line to my .bash_profile, then re-ran the rvm install command using --force, and was good to go. Thanks! – turboladen Dec 03 '11 at 20:01
  • Glad this helped! I was in the same situation and none of the other answers worked for me, so I wanted to document it. – Matt Sanders Dec 05 '11 at 17:31
  • This also worked for me after all previous suggestions had failed. – Cory Schires Feb 13 '12 at 21:39
  • As an update, I recently reinstalled Lion and was able to get everything working without installing Xcode at all. So, if you haven't installed it yet you may want to just try the OSX gcc installer and see if you have what you need. – Matt Sanders Mar 20 '12 at 18:08
  • This worked for me thank goodness. Was able to get 1.8.7 and rails 2.3.8 installed for my legacy sites – Richard Brown Mar 26 '12 at 00:53
22

If that still doesn't work add --force. So this becomes:

CC=/usr/bin/gcc-4.2 rvm install ruby-1.8.7 --force

  • Yes, if you started the install without gcc-4.2, it will pick up where it left off the second time around. So you need --force to wipe out the stuff you already compiled with llvm and start over. – Lawrence Jul 28 '11 at 17:46
  • I blew away my ~/.rvm and still had to use --force ty Hans – Scott Smith Aug 20 '11 at 01:46
  • Thanks Hans, --force is what I was looking for too – Stu Sep 27 '11 at 10:41
  • 1
    Often using `make clean` from the command-line in the installation directory is the more appropriate command to use instead of `--force`. Force ignores errors, and errors are something to pay attention to. So be careful. – the Tin Man Jan 23 '12 at 16:02
7

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"

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
HeroicEric
  • 876
  • 5
  • 13
6

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
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
KARASZI István
  • 30,900
  • 8
  • 101
  • 128
  • 4
    The GitHub URL has changed. The command is now `brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb` instead. – Matthew Ratzloff Mar 31 '12 at 07:21
4

Instead of "export CC=/usr/bin/gcc-4.2" do "export CC=gcc" (xCode 4.2.x should be installed).

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
xpepermint
  • 35,055
  • 30
  • 109
  • 163
2

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.

Rimian
  • 36,864
  • 16
  • 117
  • 117
1

Using macport and ruby-1.9.x version. I did successfully install rails with ruby gem.

Henry Kim
  • 21
  • 5
1

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.

miry
  • 318
  • 2
  • 11
0

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)

Community
  • 1
  • 1
Brad Gessler
  • 2,744
  • 4
  • 23
  • 22
0

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 :)

Beltran
  • 1,150
  • 6
  • 10
0

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")

antyrat
  • 27,479
  • 9
  • 75
  • 76
0

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.

Aidan Feldman
  • 5,205
  • 36
  • 46
  • Remember that the system installed Ruby 1.8.7 is there for Apple's use. We can piggy-back on it but be careful updating gems. – the Tin Man Jan 23 '12 at 16:06
0

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.

Mark Maglana
  • 604
  • 7
  • 7