Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

ruby - error: failed to build gem native extension when installing rails on mac mountian lion os

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...