错误:在mac mountain lion os上安装rails时无法构建gem native扩展

时间:2012-08-03 20:35:21

标签: ruby-on-rails ruby ruby-c-extension

我最近更新了Mountain Lion并重新安装了Ruby,但是当我尝试运行测试Rails应用程序时,我收到一条错误消息,指出我的系统上“当前未安装Rails”。我按照它说的做,键入sudo gem install rails并获取:

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

但是当我检查安装哪个rails版本时,我得到的是:

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.

我也试过gem install rails并获得:

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

4 个答案:

答案 0 :(得分:40)

我发现你在 OS X 10.8.2(Mountain lion)上使用 rvm ruby​​ 1.9.3 rails引用的一些宝石可能需要 / usr / bin 中的 gcc-4.2 来构建本机扩展。

在Mountain Lion中,即使安装了 Xcode 4.5 CLI工具(打开菜单XCode - Preferences..Download - &gt;命令行工具),您也可以获得 / usr / bin / gcc < / strong>但不是 /usr/bin/gcc-4.2 ;不幸的是某些原生扩展的构建过程依赖于/usr/bin/gcc-4.2

但是我只是在你的环境中顺利安装了导轨。 我之前修改了Carina C. Zona的博客文章Fix for “make: /usr/bin/gcc-4.2: No such file or directory”中所讨论的环境,即:

  • 确保您已安装Homebrew

      

    brew --version

    应报告0.9.3或更高

      

    brew更新

  • 现在你可以安装gcc-4.2并创建一个符号链接,这个链接在构建系统中被认为是

      

    brew tap homebrew / dupes

         

    brew install apple-gcc42

         

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

  • 现在您已准备好成功安装rails

      

    gem install rails

你应该得到像这样的输出

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

答案 1 :(得分:9)

@Franco是正确的:“原生扩展”构建脚本期望/usr/bin/gcc-4.2,这在OS X Mountain Lion中不存在。

  • 如果您从prevoius OS X版本升级到Mountain Lion ,那么您可能已经拥有了gcc。在这种情况下,只需创建一个符号链接到gcc:sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
  • 如果您有全新安装Mountain Lion ,那么您可能根本没有gcc。在这种情况下,您需要{@ 3}} @Franco解释。

这不是特定的“rails”宝石问题。任何构建“原生扩展”的gem都会失败:

  

Gem :: Installer :: ExtensionBuildError:错误:无法构建gem原生扩展。 [...]   您必须先安装开发工具。

在我的情况下,我试图安装install gcc,这取决于名为RedCloth的东西。

答案 2 :(得分:4)

我也和Mountain Lion一起讨论了这个问题。安装失败的宝石是json。为了解决这个问题,我安装了xcode CLI工具,然后将已安装的gcc(i686-apple-darwin11-llvm-gcc-4.2)符号链接为/usr/bin/gcc-4.2。一旦完成,它就会起作用。

在尝试安装另一个gem时,我遇到了类似的问题,其中本机构建步骤抱怨缺少g ++ - 4.2。我用上面的gcc-4.2完全相同,并且它有效。

更新:使用最新RVM的OSX Mavericks

使用最新的OSX 10.9和最新的RVM,这些问题似乎已经消失。所以,升级的时间。

答案 3 :(得分:3)

首先尝试使用this

他假设你已经有了自制软件。如果不这样做,您可以从here

获取