31

我最近更新到 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

4 回答 4

40

我看到您在OS X 10.8.2 (Mountain lion)上使用ruby​​ 1.9.3使用rvm 轨道引用的某些 gem 可能需要/usr/bin中的gcc-4.2来构建本机 estension。

在 Mountain Lion 中,即使安装了Xcode 4.5 CLI 工具(打开菜单 XCode - Preferences..Download -> Command Line Tools),您也会得到/usr/bin/gcc而不是/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”</a>,即:

你应该得到这样的输出

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...
于 2012-11-01T11:26:32.057 回答
9

/usr/bin/gcc-4.2@Franco 是正确的: OS X Mountain Lion 中不存在“本机扩展”构建脚本 expect 。

  • 如果您从以前的 OS X 版本升级到 Mountain Lion ,那么您可能已经拥有 gcc。在这种情况下,只需创建一个指向 gcc 的符号链接:sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
  • 如果您有全新安装的 Mountain Lion,那么您可能根本没有 gcc。在这种情况下,您需要按照@Franco 的说明安装 gcc 。

这不是专门的“rails”宝石问题。任何构建“本机扩展”的 gem 都会失败:

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

就我而言,我试图安装octopress,这取决于称为 RedCloth 的东西。

于 2012-12-09T18:14:05.587 回答
4

我也遇到了这个问题,山狮。安装失败的 gem 是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,这些问题似乎已经消失。所以,是时候升级了。

于 2013-01-13T17:14:29.183 回答
3

尝试先解决这个问题

他假设您已经有自制软件。如果你不这样做,你可以从这里得到它

于 2012-08-04T09:20:02.950 回答