error: failed to build gem native extension when installing rails on mac mountian lion os
Asked Answered
P

4

31

I've recently updated to Mountain Lion and re-installed Ruby, but when I try to run a test Rails app, I get an error message that says that "Rails is not currently installed" on my system. I do what it says, type sudo gem install rails and get:

cleared faster_require caches due to new gem install...
Successfully installed rails-3.2.7
1 gem installed
Installing ri documentation for rails-3.2.7...
Installing RDoc documentation for rails-3.2.7...

But when I check to see which rails version is install, here is what I get:

Rails is not currently installed on this system. To get the latest version, simply type:

    $ sudo gem install rails

You can then rerun your "rails" command.

I've also tried gem install rails and get:

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

        /Users/aileen/.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/aileen/.rvm/gems/ruby-1.9.3-p194@rails327/gems/json-1.7.4 for inspection.
Results logged to /Users/aileen/.rvm/gems/ruby-1.9.3-p194@rails327/gems/json-1.7.4/ext/json/ext/generator/gem_make.out
Protanopia answered 3/8, 2012 at 20:35 Comment(1)
There is a button that says: "Click to accept this answer because it solved your problem or was the most helpful in finding your solution.". If you still need help, improve the questions if it is related or create another question.Terriss
T
40

I see that you are using ruby 1.9.3 using rvm on OS X 10.8.2 (Mountain lion) It's possible that some gems referenced by rails need gcc-4.2 in /usr/bin to build native estension.

In Mountain Lion , even after installing Xcode 4.5 CLI tools ( opening the menu XCode - Preferences..Download -> Command Line Tools ) you get /usr/bin/gcc but not /usr/bin/gcc-4.2; unfortunately the build process of some native extension relies on /usr/bin/gcc-4.2

However I just installed rails smoothly on an environment such as your. I previously fixed the environment as discussed in the Carina C. Zona's blog post: Fix for “make: /usr/bin/gcc-4.2: No such file or directory”, that is:

  • make sure you have installed Homebrew

    brew --version

    should report 0.9.3 or greater

    brew update

  • now you can install gcc-4.2 and create a symbolink link where is aspected by the build system

    brew tap homebrew/dupes

    brew install apple-gcc42

    sudo ln -s /usr/local/bin/gcc-4.2 /usr/bin/gcc-4.2

  • now you're ready to successfully install rails

    gem install rails

You should get output something like this

Fetching: i18n-0.6.1.gem (100%)
Fetching: activesupport-3.2.8.gem (100%)
Fetching: builder-3.0.4.gem (100%)
Fetching: activemodel-3.2.8.gem (100%)
Fetching: rack-cache-1.2.gem (100%)
Fetching: rack-test-0.6.2.gem (100%)
Fetching: journey-1.0.4.gem (100%)
Fetching: hike-1.2.1.gem (100%)
Fetching: sprockets-2.1.3.gem (100%)
Fetching: erubis-2.7.0.gem (100%)
Fetching: actionpack-3.2.8.gem (100%)
Fetching: arel-3.0.2.gem (100%)
Fetching: tzinfo-0.3.34.gem (100%)
Fetching: activerecord-3.2.8.gem (100%)
Fetching: activeresource-3.2.8.gem (100%)
Fetching: polyglot-0.3.3.gem (100%)
Fetching: treetop-1.4.12.gem (100%)
Fetching: mail-2.4.4.gem (100%)
Fetching: actionmailer-3.2.8.gem (100%)
Fetching: rack-ssl-1.3.2.gem (100%)
Fetching: railties-3.2.8.gem (100%)
Fetching: rails-3.2.8.gem (100%)
Successfully installed i18n-0.6.1
Successfully installed activesupport-3.2.8
Successfully installed builder-3.0.4
Successfully installed activemodel-3.2.8
Successfully installed rack-cache-1.2
Successfully installed rack-test-0.6.2
Successfully installed journey-1.0.4
Successfully installed hike-1.2.1
Successfully installed sprockets-2.1.3
Successfully installed erubis-2.7.0
Successfully installed actionpack-3.2.8
Successfully installed arel-3.0.2
Successfully installed tzinfo-0.3.34
Successfully installed activerecord-3.2.8
Successfully installed activeresource-3.2.8
Successfully installed polyglot-0.3.3
Successfully installed treetop-1.4.12
Successfully installed mail-2.4.4
Successfully installed actionmailer-3.2.8
Successfully installed rack-ssl-1.3.2
Successfully installed railties-3.2.8
Successfully installed rails-3.2.8
22 gems installed
Installing ri documentation for i18n-0.6.1...
Building YARD (yri) index for i18n-0.6.1...
Installing ri documentation for activesupport-3.2.8...
Building YARD (yri) index for activesupport-3.2.8...
Installing ri documentation for builder-3.0.4...
Building YARD (yri) index for builder-3.0.4...
Installing ri documentation for activemodel-3.2.8...
Building YARD (yri) index for activemodel-3.2.8...
Installing ri documentation for rack-cache-1.2...
Building YARD (yri) index for rack-cache-1.2...
Installing ri documentation for rack-test-0.6.2...
Building YARD (yri) index for rack-test-0.6.2...
Installing ri documentation for journey-1.0.4...
Building YARD (yri) index for journey-1.0.4...
Installing ri documentation for hike-1.2.1...
Building YARD (yri) index for hike-1.2.1...
Installing ri documentation for sprockets-2.1.3...
Building YARD (yri) index for sprockets-2.1.3...
Installing ri documentation for erubis-2.7.0...
Building YARD (yri) index for erubis-2.7.0...
Installing ri documentation for actionpack-3.2.8...
Building YARD (yri) index for actionpack-3.2.8...
Installing ri documentation for arel-3.0.2...
Building YARD (yri) index for arel-3.0.2...
Installing ri documentation for tzinfo-0.3.34...
Building YARD (yri) index for tzinfo-0.3.34...
Installing ri documentation for activerecord-3.2.8...
Building YARD (yri) index for activerecord-3.2.8...
Installing ri documentation for activeresource-3.2.8...
Building YARD (yri) index for activeresource-3.2.8...
Installing ri documentation for polyglot-0.3.3...
Building YARD (yri) index for polyglot-0.3.3...
Installing ri documentation for treetop-1.4.12...
Building YARD (yri) index for treetop-1.4.12...
Installing ri documentation for mail-2.4.4...
Building YARD (yri) index for mail-2.4.4...
Installing ri documentation for actionmailer-3.2.8...
Building YARD (yri) index for actionmailer-3.2.8...
Installing ri documentation for rack-ssl-1.3.2...
Building YARD (yri) index for rack-ssl-1.3.2...
Installing ri documentation for railties-3.2.8...
Building YARD (yri) index for railties-3.2.8...
Installing ri documentation for rails-3.2.8...
Building YARD (yri) index for rails-3.2.8...
Installing RDoc documentation for i18n-0.6.1...
Installing RDoc documentation for activesupport-3.2.8...
Installing RDoc documentation for builder-3.0.4...
Installing RDoc documentation for activemodel-3.2.8...
Installing RDoc documentation for rack-cache-1.2...
Installing RDoc documentation for rack-test-0.6.2...
Installing RDoc documentation for journey-1.0.4...
Installing RDoc documentation for hike-1.2.1...
Installing RDoc documentation for sprockets-2.1.3...
Installing RDoc documentation for erubis-2.7.0...
Installing RDoc documentation for actionpack-3.2.8...
Installing RDoc documentation for arel-3.0.2...
Installing RDoc documentation for tzinfo-0.3.34...
Installing RDoc documentation for activerecord-3.2.8...
Installing RDoc documentation for activeresource-3.2.8...
Installing RDoc documentation for polyglot-0.3.3...
Installing RDoc documentation for treetop-1.4.12...
Installing RDoc documentation for mail-2.4.4...
Installing RDoc documentation for actionmailer-3.2.8...
Installing RDoc documentation for rack-ssl-1.3.2...
Installing RDoc documentation for railties-3.2.8...
Installing RDoc documentation for rails-3.2.8...
Trinomial answered 1/11, 2012 at 11:26 Comment(5)
This is exactly right, but homebrew isn't needed. All that is needed is to create a symlink from gcc-4.2 to gcc: sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2Amorphous
Justin's comment is absolutely right! Thanks for the clarification. My post refers to a quite common scenario to osx ruby guys which often make use of brew as package managerTrinomial
This post completely got me started with HAR <3Vetter
sudo ln -s /usr/local/bin/gcc-4.2 /usr/bin/gcc-4.2 operation not permittedBandaid
@Bandaid ; the answer apply to os x 10.8 Mountain Lion, while operation not permitted sounds like your system is os x 10.11 El Capitan: see also this question and relative answer. Can you confirm that?Trinomial
A
9

@Franco is correct: the "native extension" build scripts expect /usr/bin/gcc-4.2, which does not exist in OS X Mountain Lion.

  • If you upgraded to Mountain Lion from a prevoius OS X version, then you may already have gcc. In that case, just create a symlink to gcc: sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
  • If you have a fresh install of Mountain Lion, then you may not have gcc at all. In that case, you would need to install gcc as @Franco explains.

This is not specifically a "rails" gem issue. Any gem that builds "native extensions" fails:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. [...] You have to install development tools first.

In my case, I was trying to install octopress, which depends on something called RedCloth.

Amorphous answered 9/12, 2012 at 18:14 Comment(1)
In my case, it complained about g++-4.2 instead of gcc-4.2, but I created the same symlink as above, substituting +'s for c's, and it worked.Bauman
L
4

I ran into this issue as well, with Mountain Lion. The gem that was failing installation was json. To fix it, I installed the xcode CLI tools and then just symlinked the installed gcc (i686-apple-darwin11-llvm-gcc-4.2) as /usr/bin/gcc-4.2. Once this was done, it just worked.

While trying to install another gem, I ran into a similar issue where the native build step complained about missing g++-4.2. I symlinked this exactly the same as I did with gcc-4.2 above, and it worked.

UPDATE: OSX Mavericks with latest RVM

With the latest OSX 10.9 and latest RVM, these issues seem to have gone away. So, time to upgrade.

Lutenist answered 13/1, 2013 at 17:14 Comment(0)
P
3

Try working through this first

He assumes you already have homebrew. If you don't you can get it from here

Pileum answered 4/8, 2012 at 9:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.