2

Receiving below error while installing any package and I using

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]

Can anyone Please help in fixing this problem, as I have already tried changing the export PATH=$PATH:/ ruby path and also tried to install ruby-dev but couldn't find it on rubygems.com or through gems install ruby-dev or ruby-devel.

Sunnx
  • 71
  • 12
  • What platform are you on? I'm guessing some flavor of Linux? Have you tried using [rvm](https://rvm.io)? Ruby 1.8.7 is pretty ancient, and RubyGems 2.1.5 is pretty new, how'd you end up with that combination? – Nick Veys Oct 09 '13 at 15:35
  • Suse linux is on SLES11SP2, so we had ruby 1.8.7 and since I installed rubygem it was on 2.1.5 – Sunnx Oct 09 '13 at 23:52
  • Use some Ruby version manager like [RVM](http://rvm.io/) or [rbenv](http://rbenv.org/) (my personal choice). If you don't want to use any of these (which is bad idea) then you need to install some kind of `dev` version of Ruby that will provide headers needed for native Ruby extensions. – Hauleth Oct 29 '13 at 08:05

1 Answers1

3

I have the same problem:

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

System info:

  [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]

After running commands:

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

I see:

[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.

And i think that CentOS 6.4 at default repos does not support rails. To solve problem, we need to install ruby from sources:

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

We don't need to remove default ruby-1.8.x Just exec source /etc/profile.d/rvm.sh after rvm installed Thanks to rvm!!!

Remember! To install rails from RVM, you need after installation ruby-1.9.3 run this command:

gem update --system 1.8.25

We did this to avoid error:

/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
xakru
  • 269
  • 2
  • 4