8

I have rvm installed on my PC with the default ruby gemset being 2.4.1

rvm list
   ruby-2.4.0 [ x86_64 ]
=* ruby-2.4.1 [ x86_64 ]
   ruby-2.6.3 [ x86_64 ]

# => - current
# =* - current && default
#  * - default

I want to install rails 5 however sprockets fails to install requiring 2.5 ruby. However rails 5 should work with any ruby above 2.2.2:

gem install rails -v 5.1.4
Fetching: activesupport-5.1.4.gem (100%)
Successfully installed activesupport-5.1.4
Fetching: actionview-5.1.4.gem (100%)
Successfully installed actionview-5.1.4
Fetching: actionpack-5.1.4.gem (100%)
Successfully installed actionpack-5.1.4
ERROR:  Error installing rails:
    sprockets requires Ruby version >= 2.5.0.

I don't care about the rails 5 version. The newer the better, but all versions do give me the errors

Any idea why this might happen?

Yury Matusevich
  • 988
  • 12
  • 22
Lucian Tarna
  • 1,806
  • 4
  • 25
  • 48

3 Answers3

14

The latest (4.0.0) version of sprockets really requires ruby >= 2.5.0. Check it here

Is gem 'sprockets' in your Gemfile set to a specific version?

To manually change version of sprockets add the line bellow to your Gemfile

gem 'sprockets', '~> 3.7.2'

If you do not have a Gemfile yet try direct installation.

gem install sprockets -v 3.7.2

Yury Matusevich
  • 988
  • 12
  • 22
  • I do not have a gemfile, the folder is just empty , wanted to do a rails new but for that needed to install rails. – Lucian Tarna Oct 09 '19 at 11:52
  • I do not know why, but this doesn't work for me, but direct sprockets installation from other answer works like a charm – Drey Mar 04 '20 at 14:19
9

For those that are experiencing this without having it explicitly specified in the gemfile, another workaround is to install the previous version manually:

gem install sprockets -v 3.7.2
wrsx
  • 579
  • 3
  • 8
1

Rails 5 may only require Ruby => 2.2.2 but if you don't version gems in your Gemfile it will always pull down the latest version of the gems. A later gem version then might need a higher version of Ruby.

This however has nothing to do with rails!

Also you might have a Problem with Ruby 2.4.1 using it with Rails 5.1.4

Which Ruby on Rails is compatible with which Ruby version?

mahatmanich
  • 10,791
  • 5
  • 63
  • 82