user1622511
user1622511

Reputation: 91

Ruby on Rails on Fedora 20

I am using Fedora 20 and installed Ruby version 2.0 and Rails version 4.1.6.

I tried rails new example but got this error:

Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Using rake 10.3.2
Using i18n 0.6.11

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

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


Gem files will remain installed in /home/sntr/.gem/ruby/gems/json-1.8.1 for inspection.
Results logged to /home/sntr/.gem/ruby/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
An error occurred while installing json (1.8.1), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.1'` succeeds before bundling.
         run  bundle exec spring binstub --all
bundler: command not found: spring
Install missing gem executables with `bundle install`

I tried gem install json -v '1.8.1' or sudo yum install json ... but it didn't change, I couldn't run Rails.

Upvotes: 0

Views: 1695

Answers (4)

alex
alex

Reputation: 644

Just run bundle update at the root of the project

Upvotes: 0

Josef Strzibny
Josef Strzibny

Reputation: 31

I tried gem install json -v '1.8.1' or sudo yum install json ... but it didn't change, I couldn't run Rails.

System package would actually solve the problem, but you would need to lock its version in your Gemfile.

Perhaps you don't know that, but the whole Ruby on Rails framework is actually packaged, so running:

# yum install rubygem-rails

will install Rails for you. But since you will be most likely installing some other gems or their newer versions, install Ruby header files as well by installing the ruby-devel package:

# yum install ruby-devel

Using system Ruby package is actually a good choice that is easy to install and gives you security updates among other things. Using Ruby version manager is going to help you only if you need other version of Ruby that is not provided by your OS.

Upvotes: 1

Michael Hampton
Michael Hampton

Reputation: 10000

The problem here is that bundler doesn't use the system rubygems if newer versions are available from rubygems.org. So, even if you have rubygem-json installed from Fedora packages, if for example it's version 1.8.1, it will be ignored because version 1.8.2 is in rubygems.

The same issue occurs with several other gems, but doesn't result in bundle failing unless the gem uses native extensions (i.e. C code that needs to be compiled). Thus the json gem failed to install, but other gems will install successfully (from rubygems, not from yum).

This issue was discussed in depth on Github, and unfortunately it has no easy solution, and not one that involves Bundler. Bundler is meant to ensure that, given a Gemfile/Gemfile.lock, that it installs exactly the versions of gems given, regardless of what system it's being run on.

If you must use only system gems, then you need to create your app with rails new app --no-gemfile, install all of the necessary system gems yourself, and document which gems they are so that the gem installation can be repeated later for testing and deployment. In particular, your app will not have a Gemfile or Gemfile.lock. Typically you only need to do this if you're developing for deployment on a specific OS distribution (e.g. RHEL 7) and are only allowed to use system-provided packages anyway. This is common enough in enterprise software development. If you aren't in this scenario, you should probably not use system ruby or rubygems at all, and prefer RVM.

Upvotes: 0

Aret
Aret

Reputation: 475

Use RVM instead.

If you are still new, it gives you an option for experimenting with different versions and environments.

Upvotes: 0

Related Questions