无法构建本机gem扩展 - Rails安装

时间:2014-01-19 08:51:43

标签: ruby-on-rails ruby

我按照线程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$ 

我使用的是最新版本的gem,运行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

Ayman $

更新两次

按照以下步骤安装以下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

3 个答案:

答案 0 :(得分:3)

我解决了这个问题。

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

将我的宝石升级到最新版本后,它运行良好。

谢谢大家!

答案 1 :(得分:1)

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

rvmsudo gem install rails

修改

我的意思是'rvmsudo',而不是'sudorvm'。对不起,我正在打电话。

答案 2 :(得分:1)

总有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