2

安装任何软件包时收到以下错误,我使用

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

    /usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib64/ruby/ruby.h


Gem files will remain installed in /usr/lib64/ruby/gems/1.8/gems/atomic-1.1.14 for inspection.
Results logged to /usr/lib64/ruby/gems/1.8/gems/atomic-1.1.14/ext/gem_make.out


 # gem -v
2.1.5
 # ruby -v
ruby 1.8.7 (2008-08-11 patchlevel 72) [x86_64-linux]

任何人都可以请帮助解决这个问题,因为我已经尝试更改 export PATH=$PATH:/ ruby​​ 路径并且还尝试安装 ruby​​-dev 但在 ruby​​gems.com 或通过 gems install ruby​​-dev 找不到它或红宝石开发。

4

1 回答 1

3

我也有同样的问题:

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

/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/atomic-1.1.14 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/atomic-1.1.14/ext/gem_make.out

系统信息:

  [root@server ~]# uname -a
    Linux server.com 2.6.32-358.18.1.el6.x86_64 #1 SMP Wed Aug 28 17:19:38 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
    [root@server ~]# cat /etc/redhat-release 
    CentOS release 6.4 (Final)
    [root@server ~]# ruby -v
    ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]

运行命令后:

yum install ruby-rdoc ruby-devel -y
gem update
gem update --system

我懂了:

[root@server ~]# gem install rails
Building native extensions.  This could take a while...
Successfully installed atomic-1.1.14
Fetching: thread_safe-0.1.3.gem (100%)
Successfully installed thread_safe-0.1.3
Fetching: activesupport-4.0.0.gem (100%)
ERROR:  Error installing rails:
    activesupport requires Ruby version >= 1.9.3.

而且我认为默认存储库中的 CentOS 6.4 不支持 rails。为了解决这个问题,我们需要从源代码安装 ruby​​:

curl -L get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm requirements
rvm install 1.9.3
rvm use 1.9.3 --default
rvm rubygems current

我们不需要删除默认的 ruby​​-1.8.x 只需在 rvm 安装后 exec source /etc/profile.d/rvm.sh 感谢 rvm !!!

记住!要从 RVM 安装 rails,您需要在安装 ruby​​-1.9.3 后运行以下命令:

gem update --system 1.8.25

我们这样做是为了避免错误:

/script/../config/../vendor/rails/railties/lib/rails/gem_dependency.rb:21:in `add_frozen_gem_path': undefined method `source_index' for Gem:Module (NoMethodError)
    from ./script/../config/boot.rb:60:in `load_initializer'
    from ./script/../config/boot.rb:44:in `run'
    from ./script/../config/boot.rb:17:in `boot!'
    from ./script/../config/boot.rb:123
    from script/server:2:in `require'
    from script/server:2
于 2013-10-29T07:48:28.520 回答