Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to run a Rails 4.2 app on Ruby 2.4?

I want to try out a Rails 4.2 app on Ruby 2.4.

However, when I try doing it, I get errors about the json gem version 1.8.3 failing to install.

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/agrimm/.rbenv/versions/2.4.0-rc1/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator
/Users/agrimm/.rbenv/versions/2.4.0-rc1/bin/ruby -r ./siteconf20161223-91367-cql0ne.rb extconf.rb
creating Makefile

current directory: /Users/agrimm/.rbenv/versions/2.4.0-rc1/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR=" clean

current directory: /Users/agrimm/.rbenv/versions/2.4.0-rc1/lib/ruby/gems/2.4.0/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
generator.c:861:25: error: use of undeclared identifier 'rb_cFixnum'
    } else if (klass == rb_cFixnum) {
                        ^
generator.c:863:25: error: use of undeclared identifier 'rb_cBignum'
    } else if (klass == rb_cBignum) {
                        ^
2 errors generated.
make: *** [generator.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/agrimm/.rbenv/versions/2.4.0-rc1/lib/ruby/gems/2.4.0/gems/json-1.8.3 for inspection.
Results logged to /Users/agrimm/.rbenv/versions/2.4.0-rc1/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-14/2.4.0-static/json-1.8.3/gem_make.out

An error occurred while installing json (1.8.3), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.3'` succeeds before bundling.

which I assume is due to the unification of Fixnum and Bignum into Integer.

If I add to the Gemfile a constraint that json has to be version 2.0.0, then it complains that Rails 4.2 requires json ~> 1.7, which forbids 2.0.0.

Am I out of luck unless the maintainers of Rails decide to make a change to a non-5.x version of Rails, or the maintainers of the json gem decide to make a new non-2.x version of their gem?

like image 827
Andrew Grimm Avatar asked Dec 23 '16 09:12

Andrew Grimm


People also ask

Does Rails 5.2 support Ruby 3?

Rails 5.2 doesn't work with Ruby 3.0 #40938.

What version of Ruby does Rails support?

Rails Rails 4 requires Ruby 1.9 or later. Rails 5 requires Ruby 2.2 or later. Rails 6 requires Ruby 2.5 or later.

Does Rails support Ruby 3?

Ruby 3 has been released on 25 December 2020, and increase speed performance almost 3 times when compare with Ruby 2.0 (not latest one 2.7. 2) and also when using JIT. We will try to check live world performance using Ruby on Rails 6.

How do I install a specific version of a gem?

Use `gem install -v` You may already be familiar with gem install , but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators.


4 Answers

The json gem has a fix on the 1.8 branch. Hopefully it'll be released as a gem soon, but in the meantime you can use it directly in your Gemfile:

gem 'json', github: 'flori/json', branch: 'v1.8'

Rails has also merged a fix to the 4-2-stable branch about a week after the latest official 4.2.x gem release. Hopefully they'll release a new gem soon too, but this might help in your Gemfile:

gem 'rails', github: 'rails/rails', branch: '4-2-stable'

Finally, you may need to load arel from a git source as well:

gem 'arel', github: 'rails/arel', branch: '6-0-stable'

With those three changes I was able to boot our app and query the database, but then ran into other Integer unification related issues. Seems like this change to going to cause some waves.

like image 53
James Healy Avatar answered Oct 07 '22 18:10

James Healy


It is now possible with rails 4.2.8.rc1 (February 11th 2017)

like image 27
Joshua Avatar answered Oct 07 '22 17:10

Joshua


Upgrade rails to rails-4.2.8 .This is the first 4.2.x version that officially supports ruby-2.4

like image 7
tessie Avatar answered Oct 07 '22 18:10

tessie


It looks like it won't be possible at the moment (Although it sounds odd).

See the Changelog for the JSON gem. Json 2.0.0 adds compatibility for ruby 2.4, but rails 4.2 restricts json to 1.x

like image 4
dgmora Avatar answered Oct 07 '22 16:10

dgmora