我是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
答案 0 :(得分:11)
我有类似的问题,它通过安装命令行工具得到解决:
xcode-select --install
答案 1 :(得分:6)
符号链接并没有解决我的问题。我通过键入rvm uninstall ruby-2.0.0
卸载了之前使用rvm安装的ruby,然后键入了rvm requirements
。这个命令发现我需要一些其他的东西,比如gcc46。奇怪的是,即使我已经安装了xcode命令行工具,也需要gcc编译器,而且我的系统上肯定安装了gcc。
因此,如果通常的方法都不起作用,请给rvm requirements
一个机会!
答案 2 :(得分:1)
我猜这与this question同样存在问题。
再次尝试sudo ln -s /usr/bin/{llvm-,}gcc-4.2
和gem install rails
。
顺便说一句,您在自己的主目录中,不必使用sudo
。
答案 3 :(得分:0)
我刚遇到ruby 2.5.3
并能够通过调用以下命令来安装cairo:
PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig gem install cairo -v '1.15.2'
花点时间找到可行的方法,因为我已经安装了命令行工具,并且使用的是asdf
而不是rvm
。
感谢该主题为您提供了解决方法:https://github.com/ruby-gnome2/ruby-gnome2/issues/259#issuecomment-59751807