How to switch to truffleruby on Rails?

1.1k views Asked by At

I'd like to try running Rails 6 with TruffleRuby, so I installed truffleruby-22.0.0.2 with rbenv, added in my Gemfile ruby 'truffleruby-22.0.0.2 and ran bundle install, but that didn't work. I got an error with "... error parsing Gemfile: Illformed requirement..."

What's the right way to use Rails with TruffleRuby?

2

There are 2 answers

0
Mathieu EUSTACHY On

A long shot, but using another Ruby implementation with Rails raising this error is related to the way you declare your Ruby version in your Gemfile.

Traditional way:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.1.4'
# ...

Other Ruby implementation way example:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.1.4', :engine => 'jruby', :engine_version => '9.4.3.0'
# ...
0
frvade On

If this is still relevant: you can see here https://github.com/oracle/truffleruby/blob/master/doc/user/compatibility.md that as of now Truffle Ruby aims to be compatible with MRI Ruby 3.0.3, so it sets the RUBY_VERSION env variable to 3.0.3 and this is the value you should set in your Gemfile.

Unfortunately, when you do so rbenv can't detect that you want to use Truffle Ruby instead of MRI. So you should also run export RBENV_VERSION=truffleruby+graalvm-dev and then bundler would target to 3.0.3 while rbenv would use Truffle Ruby.

To know what is the target version detected by bundler you can specify any valid ruby version (like 3.1.2 or something) and running bundle would output more clarifying error message like this:

Your Ruby version is 3.0.3, but your Gemfile specified 3.1.2