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.
Throughout this guide we will be going through this process repeatedly.
- Run bundle install
- Hit an error because a gem
that_mri_only_gemdoes not work on JVM and is trying to build native extension
- Modify Gemfile so that
that_mri_only_gemis only included in
- If required, find a jvm compatible gem to replace it.
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
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.
Rails 5 defaults to Puma web server, but you may have other web servers installed. Modify Gemfile to limit those to
If you are using byebug or pry, they don’t run on jvm.
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.