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

4

19

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?

Velez answered 23/12, 2016 at 9:43 Comment(0)
D
15

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

Defloration answered 14/2, 2017 at 22:43 Comment(0)
R
16

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.

Radiolocation answered 26/12, 2016 at 10:10 Comment(2)
Since posting this answer, ruby 2.4 compatible versions of json (1.8.5) and arel (6.0.4) have been released. The main thing we're waiting on now is a new rails 4.2.x release.Radiolocation
.. and now rails 4.2.8 has been released, which should be enough to get apps booting on ruby 2.4. It's likely a few second and third level dependencies will print deprecations, but hopefully they're not fatalRadiolocation
D
15

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

Defloration answered 14/2, 2017 at 22:43 Comment(0)
O
7

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

Oblast answered 21/3, 2017 at 15:15 Comment(0)
C
4

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

Channa answered 23/12, 2016 at 11:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.