Rails报告错误:无法构建gem原生扩展


0

我已经安装了最新的命令行工具,并在此主题的其他线程上执行了相应的步骤。我知道这似乎是重复的,但我在这里看不到任何问题的答案:

Jacobs-MacBook-Pro:~ jacob$ sudo gem install rails
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby 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
--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=/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
--help
--clean
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/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 /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:549:in `block in try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:500:in `with_werror'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:549:in `try_compile'
from extconf.rb:80:in `nokogiri_try_compile'
from extconf.rb:87:in `block in add_cflags'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/mkmf.rb:597:in `with_cflags'
from extconf.rb:86:in `add_cflags'
from extconf.rb:336:in `<main>'


Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/nokogiri-1.6.7.2/ext/nokogiri/gem_make.out

Answers:


1
  1. 首先,检查您是否安装了Xcode
  2. 其次,如果您的Mac中已经有Xcode,请使用以下命令:

    CC=gcc rvm install-version
    

CC=gcc rvm install-1.9.3

Mac OS中出现此错误的原因是您的Ruby无法获取C头文件

希望,这适用于所有的Macbook。

它的工作在El Capitan,ruby 1.9.3,rails 3.2,mysql 5.7


那很有效。当我去安装自制软件后,我在终端收到一条消息,说我没有同意Xcode中的许可条款。我已经有一段时间了,但我没有在这台电脑上打开它。我打开它,并同意条款/条件,然后一切顺利进行轨道。我不确定这是否是阅读这篇文章的其他人的相关信息,但这是这个过程的问题的一部分。
rbApostate

此外,我在运行“CC = gcc ...”后收到此消息:“没有二进制红宝石可用于:osx / 10.11 / x86_64 / ruby​​-2.0.0.p648。继续编译。请阅读'rvm help mount'获得有关二元红宝石的更多信息。“这会成为一个问题,还是我还需要做些什么呢?
rbApostate

我不认为这对你来说是否会成为一个问题。如果它让我们知道,但“同意在Xcode中许可条款”确实是一件大事。
Aditya Shukla

请回答,如果它适合您,请勾选答案。
Aditya Shukla

我同意了条款,安装了自制软件,然后我就可以安装ruby而不会出现任何进一步的错误。任务完成。
rbApostate
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.