It’s 2018 and running Rails on Windows is still as painful as many years ago. Probably because all the Ruby people love and use a Mac. JRuby is a good alternative to MRI and does not require building native extensions. This is a quick note on how to modify a Rails 5 project so that it runs on both MRI and JRuby.
Adding JRuby support, an iterative process
Throughout this guide we will be going through this process repeatedly.
- Run bundle install
- Hit an error because a gem
that_mri_only_gem
does not work on JVM and is trying to build native extension - Modify Gemfile so that
that_mri_only_gem
is only included inmri
platform - If required, find a jvm compatible gem to replace it.
The pg
gem
Most likely you are running a Rails project that uses PostgreSQL for data persistence. Modify Gemfile so that pg is only included with mri
platform and use activerecord-jdbcpostgresql-adapter
for jruby
platform. At the time this article is written, support for activerecord 5.1.0
on activerecord-jdbcpostgresql-adapter
is not yet released. We are using the latest code from master branch. This is not ideal, but works as a temporal workaround.
1 | Index: Gemfile |
Other Rack servers
Rails 5 defaults to Puma web server, but you may have other web servers installed. Modify Gemfile to limit those to mri
only.
1 | Index: Gemfile |
Debugging tools
If you are using byebug or pry, they don’t run on jvm.
1 | Index: Gemfile |
Now your Rails project should be able to run on both MRI and JRuby, if it still doesn’t. Follow the iterative process and fix incompatiblity with replacement gems.