OS X 10.10 Yosemite安装Rails错误

时间:2015-09-07 11:18:44

标签: ruby-on-rails ruby rvm

我正在尝试在OS X 10.10 Yosemite上安装rails我遇到这些错误:
我已经安装了XCode Command Line Tools和Homebrew,并且有问题。

ERROR:  Error installing rails:
ERROR: Failed to build gem native extension.

/usr/local/opt/ruby/bin/ruby -r ./siteconf20150908-43862-19795mu.rb extconf.rb
checking if the C compiler accepts ... *** 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
--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=/usr/local/Cellar/ruby/2.2.3/bin/$(RUBY_BASE_NAME)
--help
--clean
/usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/mkmf.rb:571:in `block in try_compile'
from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/mkmf.rb:522:in `with_werror'
from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/mkmf.rb:571:in `try_compile'
from extconf.rb:80:in `nokogiri_try_compile'
from extconf.rb:87:in `block in add_cflags'
from /usr/local/Cellar/ruby/2.2.3/lib/ruby/2.2.0/mkmf.rb:619:in `with_cflags'
from extconf.rb:86:in `add_cflags'
from extconf.rb:337:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /Users/Nitzan/.rvm/gems/ruby-2.2.1/gems/nokogiri-1.6.6.2 for inspection.
Results logged to /Users/Nitzan/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-14/2.2.0/nokogiri-1.6.6.2/gem_make.out
Nitzans-MBP:~ Nitzan$ 

2 个答案:

答案 0 :(得分:2)

有同样的问题。事实证明,即使我安装了开发工具,我也不同意条款和条件。

尝试运行'gcc'命令。就我而言,我收到了这条消息

  

同意Xcode / iOS许可证需要管理员权限   通过sudo以root身份重新运行。

用sudo重新运行相同的命令就可以了。

答案 1 :(得分:0)

您的计算机上似乎已经安装了rbenv和rvm。选择一个并删除另一个,或删除两个并再次安装干净的表上的首选。为简单起见,我会保留rvm,检查其网站:https://rvm.io/。 干杯!

更新:现在看来您已经安装了一个红宝石,现在通过homebrew。也删除它。使用RVM的关键是,对于您的项目,您需要多个版本的ruby并且只使RVM管理您当前的ruby,不要使用任何其他rubies(系统/自制程序)。

RVM速成课程:

  1. rvm current - 显示您当前使用的ruby和gemset(如果 任何)。这是非常重要的信息,非常重要,我 建议你把它放到你的shell提示符中(如果你做了很多红宝石 编程),所以当你运行任何shell命令时,你都知道哪个 ruby / gemset配对你正在使用。使用rvm-prompt命令来放置它 进入你的shell(只需google for&#34;自定义shell提示符&#34;关于如何 这样做,我在这里不会深入研究这个主题。)
  2. rvm requirements - 安装所有编译所需的要求 您的平台上的红宝石(这应该是自动完成的 你运行rvm install <ruby version>
  3. rvm list - 将列出所有已安装的红宝石并显示哪些红宝石 一个是默认的,你当前正在使用哪个。
  4. rvm list known - 将显示所有推荐的ruby版本 可以安装,现在看看MRI部分,你不需要 其他一切。
  5. rvm install <ruby-version - 显然,安装某些版本的ruby。
  6. rvm use <ruby-version>@<gemset> - 切换到某些<ruby-version> 并且,可选地<gemset>。如果您的目录包含.ruby-version和/或.ruby-gemset文件(见下文),您可以使用以下技巧:rvm use . - 将使当前目录的这些文件中定义的RVM选取设置。
  7. 所以,当我不确定我是否使用正确的红宝石时,我会这样做:

    ~/projects ♥ rvm current
    ruby-2.2.1
    ~/projects ♥ rvm use ruby-2.2.0@myapp
    Using /Users/alexey/.rvm/gems/ruby-2.2.0 with gemset myapp
    ~/projects ♥
    

    如果放置在项目特殊文件rvm.ruby-version的根目录中,可以让.ruby-gemset自动切换ruby版本和gemsets(请注意前面的.的文件名)并将您的ruby版本放到.ruby-version,将您的宝石版放到.ruby-gemset,如下所示:

    ruby-2.1.4@active_interaction in ~/projects/active_interaction on master ♥ cat .ruby-version 
    ruby-2.1.4
    ruby-2.1.4@active_interaction in ~/projects/active_interaction on master ♥ cat .ruby-gemset 
    active_interaction
    ruby-2.1.4@active_interaction in ~/projects/active_interaction on master ♥ cd ..
    ruby-2.2.0@pgm-rails2 in ~/projects ♥ cd -
    ~/projects/active_interaction
    ruby-2.1.4@active_interaction in ~/projects/active_interaction on master ♥ 
    

    注意切换目录时,提示符中的ruby版本是如何变化的。

    提交.ruby-version文件以确保项目中的每个人都使用相同的ruby并且提交.ruby-gemset也很有用,因为它可能会干扰使用其他开发人员的一些自定义设置(如果他们有一个带有其他名称的宝石集,或者根本不使用任何宝石集。)

    现在,你现在需要做什么:

    1. 通过rvm。
    2. 安装您想要的ruby版本
    3. 转到项目文件夹并准备.ruby-version和(可选).ruby-gemset文件。
    4. 切换到这些版本并确保正确切换。
    5. 现在,你可以运行你想要的任何命令,rvm将使用你想要的红宝石。