【问题标题】:Failed to build native gem extension - Rails Install无法构建原生 gem 扩展 - Rails 安装
【发布时间】:2014-01-19 08:51:42
【问题描述】:

我按照线程 here 上的说明进行操作,但仍然收到以下错误消息:

Ayman$ rails -v
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.
Ayman$ gem install rails
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
ERROR: Failed to build gem native extension.

/Users/Ayman/.rvm/rubies/ruby-2.0.0-p353/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/Ayman/.rvm/rubies/ruby-2.0.0-p353/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/Ayman/.rvm/rubies/ruby-2.0.0-p353/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/Ayman/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/mkmf.rb:519:in  `try_link0'
from /Users/Ayman/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/mkmf.rb:817:in `try_run'
from extconf.rb:26:in `<main>'


Gem files will remain installed in /Users/Ayman/.rvm/gems/ruby-2.0.0-p353/gems/atomic-1.1.14 for inspection.
Results logged to /Users/Ayman/.rvm/gems/ruby-2.0.0-p353/gems/atomic-1.1.14/ext/gem_make.out

Ayman$ 

我正在使用最新版本的 gems,运行 ruby​​ 2.0.0 和 Mac 10.8。

关于我做错了什么的任何线索?

更新

所以我按照以下步骤安装了 Xcode 命令行工具,但仍然收到以下错误消息:

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

/Users/Ayman/.rvm/rubies/ruby-2.0.0-p353/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/Ayman/.rvm/rubies/ruby-2.0.0-p353/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/Ayman/.rvm/rubies/ruby-2.0.0-p353/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/Ayman/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/mkmf.rb:519:in     `try_link0'
from /Users/Ayman/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/mkmf.rb:817:in `try_run'
from extconf.rb:26:in `<main>'


Gem files will remain installed in /Users/Ayman/.rvm/rubies/ruby-2.0.0-    p353/lib/ruby/gems/2.0.0/gems/atomic-1.1.14 for inspection.
Results logged to /Users/Ayman/.rvm/rubies/ruby-2.0.0-  p353/lib/ruby/gems/2.0.0/gems/atomic-1.1.14/ext/gem_make.out

艾曼$

更新两次

按照以下内容安装 rbenv:

Ayman$ brew update
Updated Homebrew from 8e60080c to e7a77f80.
==> Updated Formulae
reposurgeon
Ayman$ brew install rbenv ruby-build
Warning: rbenv-0.4.0 already installed
Warning: ruby-build-20140110.1 already installed
Ayman$ echo 'eval "$(rbenv init - --no-rehash)"' >> ~/.bash_profile
Ayman$ ~/.bash_profile
-bash: /Users/Ayman/.bash_profile: Permission denied
Ayman$ rbenv install 2.1.0
Downloading ruby-2.1.0.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/9e6386d53f5200a3e7069107405b93f7
Installing ruby-2.1.0...
Installed ruby-2.1.0 to /Users/Ayman/.rbenv/versions/2.1.0

Ayman$ rbenv rehash
Ayman$ rbenv global 2.1.0
Ayman$ gem install rails bundler --no-ri --no-rdoc
ERROR:  While executing gem ... (Errno::EACCES)
Permission denied - /Users/Ayman/.rvm/gems/ruby-2.0.0-p353/gems/atomic- 1.1.14/test/test_atomic.rb

【问题讨论】:

  • Xcode命令行工具安装了吗?
  • 是的,我已经安装了 Xcode
  • stackoverflow.com/questions/9353444/… 应该可以帮到你。
  • 好的,所以我安装了命令行工具,重新启动计算机,并完成了上面链接的线程中的步骤,但我仍然遇到同样的错误。什么给了?
  • 您没有使用sudo 作为您的命令,您确实应该使用,否则您将没有必要的权限。

标签: ruby-on-rails ruby


【解决方案1】:

我解决了这个问题。

原来我使用的是过时版本的 gems。

一旦我将我的 gem 升级到最新版本,它就可以正常工作了。

谢谢大家!

【讨论】:

    【解决方案2】:

    尝试 rvmsudo 使用您的 rvm 并拥有 root 权限,可能是这样的:

    rvmsudo gem install rails
    

    编辑

    我的意思是“rvmsudo”,而不是“sudorvm”。抱歉打错了,我在打电话。

    【讨论】:

    • Ayman$ sudorvm gem install rails -bash: sudorvm: command not found
    • 刚刚尝试使用rvmsudo 而不是sudorvm 并且成功并提示输入密码并开始初始化,但随后返回与以前相同的错误消息。
    • 我刚刚又试了一次,现在我得到了ERROR: While executing gem ... (Gem::RemoteFetcher::UnknownHostError) no such name (http://api.rubygems.org/quick/Marshal.4.8/minitest-4.7.5.gemspec.rz)
    【解决方案3】:

    总有rbenv 可以跳过所有麻烦的 sudo 和权限。用户本地的一切。 Why rbenv?

    brew update
    brew install rbenv ruby-build
    
    # if you dont have the init in your profile run the following:
    echo 'eval "$(rbenv init - --no-rehash)"' >> ~/.bash_profile
    source ~/.bash_profile
    
    # install a ruby
    rbenv install 2.1.0
    # you need to rehash after installing a ruby version or a global gem
    rbenv rehash
    # this will set 2.1.0 as your default ruby version in shell
    rbenv global 2.1.0
    
    # now try installing rails
    gem install rails bundler --no-ri --no-rdoc
    rbenv rehash
    

    【讨论】:

    • 我下载了 rbenv 但似乎找不到安装 rails 的命令。所有文档都告诉我只需运行 gem install rails 并返回相同的错误消息。
    • 当我尝试 rbenv install rails 它告诉我 ruby-build definition not found: rails 所以我列出了可用的版本:Ayman$ rbenv install --list Available versions: 1.8.6-p383 1.8.6-p420 1.8.7-p249 1.8.7-p302 1.8.7-p334 1.8.7-p352 1.8.7-p357 1.8.7-p358 1.8.7-p370 1.8.7-p371 1.8.7-p374 1.8.7-p375 1.9.1-p378 1.9.1-p430 1.9.2-p0 1.9.2-p180 1.9.2-p290 1.9.2-p318 1.9.2-p320 1.9.2-p326 1.9.3-dev 1.9.3-p0 1.9.3-p125 1.9.3-p194 1.9.3-p286
    • ` 1.9.3-p327 1.9.3-p362 1.9.3-p374 1.9.3-p385 1.9.3-p392 1.9.3-p429 1.9.3-p448 1.9.3-p484 1.9 .3-preview1 1.9.3-rc1 2.0.0-dev 2.0.0-p0 2.0.0-p195 2.0.0-p247 2.0.0-p353 2.0.0-preview1 2.0.0-preview2 2.0.0-rc1 2.0 .0-rc2 2.1.0 2.1.0-dev 2.1.0-preview1 2.1.0-preview2 2.1.0-rc1 2.2.0-dev`
    • ` jruby-1.5.6 jruby-1.6.3 jruby-1.6.4 jruby-1.6.5 jruby-1.6.5.1 jruby-1.6.6 jruby-1.6.7 jruby-1.6.7.2 jruby -1.6.8 jruby-1.7.0 jruby-1.7.0-preview1 jruby-1.7.0-preview2 jruby-1.7.0-rc1 jruby-1.7.0-rc2 jruby-1.7.1 jruby-1.7.10 jruby-1.7 .2 jruby-1.7.3 jruby-1.7.4 jruby-1.7.5 jruby-1.7.6 jruby-1.7.7 jruby-1.7.8 jruby-1.7.9 maglev-1.0.0 maglev-1.1.0-dev 磁悬浮-2.0.0-dev mruby-dev rbx-1.2.4 rbx-2.0.0 rbx-2.0.0-dev rbx-2.0.0-rc1 rbx-2.1.0 rbx-2.1.1 rbx-2.2.0 rbx- 2.2.1 rbx-2.2.2 rbx-2.2.3`
    • ree-1.8.6-2009.06 ree-1.8.7-2009.09 ree-1.8.7-2009.10 ree-1.8.7-2010.01 ree-1.8.7-2010.02 ree-1.8.7-2011.03 ree-1.8.7-2011.12 ree-1.8.7-2012.01 ree-1.8.7-2012.02 topaz-dev
    猜你喜欢
    • 2012-09-15
    • 1970-01-01
    • 2014-05-11
    • 2023-03-19
    • 1970-01-01
    • 2014-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多