7

I'm new to Terminal so please bear with me. Completed installing the following successfully (in this particular order):

  • xCode 4.5
  • RVM 1.16
  • GCC 4.2.1
  • Ruby 1.9.3

When trying to install Rails ("gem install rails") the installation starts but is then interrupted with an error: "Failed to build gem native extension". No idea what this refers to. Ideas? Something else I need to install beforehand?
On my first attempt to install Rails I accidentally ran it with sudo. Will this affect anything?

Edit: And the output -

Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

        /Users/staffanestberg/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
creating Makefile

make
compiling generator.c
make: /usr/bin/gcc-4.2: No such file or directory
make: *** [generator.o] Error 1

Gem files will remain installed in /Users/staffanestberg/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5 for inspection.
Results logged to /Users/staffanestberg/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5/ext/json/ext/generator/gem_make.out


Edit: Solved using iouri's suggestion. Add export CC=gcc in .bash-profile then create a symlink for the correct compiler,

sudo ln -sf /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2
Staffan Estberg
  • 6,795
  • 16
  • 71
  • 107
  • Can you post the relevant part of the build output? – Timo Geusch Oct 02 '12 at 14:03
  • But of course, see updated post. – Staffan Estberg Oct 02 '12 at 14:06
  • 1
    That's a bit weird - I just checked on my Mac here with the latest XCode and gcc is /usr/bin/gcc, not /usr/bin/gcc-4.2. Alas, I have no idea where the configuration gets gcc-4.2 from. And no, I don't know that you can change it during the install. However you might be able to override the configured compiler by setting the CC environment variable before you try to build the gem. – Timo Geusch Oct 02 '12 at 14:10
  • Ok. Thanks for looking into it. – Staffan Estberg Oct 02 '12 at 14:11
  • 2
    I know there is tons of people having issues with compiling Ruby on Rails with the GCC 4.2 on Apple's Mac... Take a look at this maybe? http://stackoverflow.com/questions/11710568/os-x-10-8-error-trying-to-exec-usr-bin-i686-apple-darwin11-gcc-4-2-1-inst – MrYoshiji Oct 02 '12 at 15:15
  • Thanks for the link to that other post, one of the comments solved my issue! See updated post. – Staffan Estberg Oct 02 '12 at 20:15
  • Thanks the link command solved it for me. BTW I didn't need to do the export CC. – jackocnr Dec 06 '12 at 13:45
  • This is a helpful article when it comes to this sort of thing. Helped me understand what was going on a bit more: http://patshaughnessy.net/2011/10/31/dont-be-terrified-of-building-native-extensions – kingsfoil Jan 22 '16 at 21:14

2 Answers2

8

Make sure you have command line tools for Xcode installed first, Xcode > Preferences > Downloads > Components. Then add this line to your .bash_profile file in your home folder ~/.bash_profile:

export CC=gcc

Double check that you have gcc (probably a symlink) in your /usr/bin (most likely), and that it is pointing to a valid gcc compiler, ex: gcc -> llvm-gcc-4.2

You might have to restart your terminal for this change to take affect.

iouri
  • 2,919
  • 1
  • 14
  • 11
  • Thanks! That turned out to be exactly what I needed. See updated post. – Staffan Estberg Oct 02 '12 at 20:15
  • I didn't have to touch the bash_profile. Just typing `xcode-select --install` seems to have fixed it. The [Stackoverflow thread on installing Rails on Mavericks](http://stackoverflow.com/questions/19580685/installing-rails-on-mavericks) was helpful. – Oliver Schafeld May 08 '14 at 12:59
5

Ruby is not fully ready for LLVM compilation, this includes clang, there is at least one known isue with Fibers, but depending on LLVM version other problems might appear.

The right way to fix it is to get gcc-4.2 there are many ways for it and the best ones are described in requirements:

rvm get stable
rvm reload
rvm requirements run
rvm reinstall 1.9.3
mpapis
  • 52,729
  • 14
  • 121
  • 158