4

我是 Ruby on Rails 的新手,安装时出现以下错误。

请注意,我已经安装了最新的 Xcode 并安装了命令行工具,并且我使用的是 OSX 10.8.4。我也安装了 Ruby 2.0.0。

-bash-3.2$ sudo gem install rails
Password:
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
ERROR: Failed to build gem native extension.

/Users/WillieTran/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
*** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:

--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/WillieTran/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
--with-atomic_reference-dir
--without-atomic_reference-dir
--with-atomic_reference-include
--without-atomic_reference-include=${atomic_reference-dir}/include
--with-atomic_reference-lib
--without-atomic_reference-lib=${atomic_reference-dir}/
/Users/WillieTran/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/mkmf.rb:434:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/WillieTran/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/mkmf.rb:519:in `try_link0'
from /Users/WillieTran/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/mkmf.rb:817:in `try_run'
from extconf.rb:24:in `<main>'


Gem files will remain installed in /Users/WillieTran/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/atomic-1.1.12 for inspection.
Results logged to /Users/WillieTran/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/atomic-1.1.12/ext/gem_make.out
4

4 回答 4

12

I had similar problem and it gets solved by installing command line tools:

xcode-select --install
于 2015-04-02T00:20:14.920 回答
6

符号链接并没有为我解决问题。我通过键入卸载了我以前使用 rvm 安装的 ruby​​,rvm uninstall ruby-2.0.0然后键入rvm requirements. 这个命令发现我还需要一些其他的东西,比如gcc46。奇怪的是需要 gcc 编译器,即使我已经安装了 xcode 命令行工具,而且 gcc 肯定安装在我的系统上。

所以,如果通常的方法都不起作用,请rvm requirements试一试!

于 2013-10-19T06:01:46.677 回答
1

我想这个问题也有同样的问题

再试sudo ln -s /usr/bin/{llvm-,}gcc-4.2一次gem install rails

顺便说一句,您在自己的主目录中,您不必使用sudo.

于 2013-08-07T05:41:15.923 回答
0

我刚刚遇到了这个问题,ruby 2.5.3并且能够通过调用来安装 cairo:

PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig gem install cairo -v '1.15.2'

花了一段时间才找到有用的东西,因为我已经安装了命令行工具,并且正在使用asdfnot rvm

感谢此线程帮助修复:https ://github.com/ruby-gnome2/ruby-gnome2/issues/259#issuecomment-59751807

于 2019-06-24T03:33:36.513 回答