Skip Navigation
Show nav
Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
    • .NET
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
Hide categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Developer Tools
    • Command Line
    • Heroku VS Code Extension
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration (Heroku Flow)
    • Continuous Integration
  • Language Support
    • Node.js
      • Working with Node.js
      • Node.js Behavior in Heroku
      • Troubleshooting Node.js Apps
    • Ruby
      • Rails Support
      • Working with Bundler
      • Working with Ruby
      • Ruby Behavior in Heroku
      • Troubleshooting Ruby Apps
    • Python
      • Working with Python
      • Background Jobs in Python
      • Python Behavior in Heroku
      • Working with Django
    • Java
      • Java Behavior in Heroku
      • Working with Java
      • Working with Maven
      • Working with Spring Boot
      • Troubleshooting Java Apps
    • PHP
      • PHP Behavior in Heroku
      • Working with PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
    • .NET
      • Working with .NET
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
      • Migrating to Heroku Postgres
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • AI
    • Model Context Protocol
    • Vector Database
    • Heroku Inference
      • Inference Essentials
      • AI Models
      • Inference API
      • Quick Start Guides
    • Working with AI
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Private Spaces
      • Infrastructure Networking
    • Compliance
  • Heroku Enterprise
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Language Support
  • Ruby
  • Rails Support
  • Moving an Existing Rails App to Run on JRuby

Moving an Existing Rails App to Run on JRuby

English — 日本語に切り替える

Last updated December 04, 2024

Table of Contents

  • Install JRuby locally
  • Specify JRuby in your gemfile
  • Replace your server with JRuby compatible Server
  • JDBC Database Drivers
  • Replace jRuby Incompatible Gems
  • Twitter Bootstrap
  • Deploy to Heroku
  • Troubleshooting

JRuby is an implementation of Ruby written to run on the JVM. JRuby is written to be compatible with MRI ruby. There are some differences in the implementations to be aware of. One of the most notable is that since the JVM does not have a global VM lock, you can run multiple threads of Ruby code concurrently. MRI is written in C and supports native C extensions, while JRuby does have support for running these extensions it can be a point of incompatibility in code.

This article shows how to convert an existing Rails project that works on Heroku to run on JRuby. It uses JRuby 1.7.16 for consistency, to see all supported versions please reference the supported Ruby Versions article. Using the latest supported version will likely provide the best application performance.

JRuby is known to consume more memory than MRI. You may want to run standard-2x dynos for optimal performance.

Install JRuby locally

If you use RVM you can install JRuby using the latest RVM version

$ rvm get latest

Once you have the latest RVM installed install jruby locally. If you wanted to install version 1.7.16 you could run:

$ rvm install jruby 1.7.16

Now you should be able to use JRuby locally:

$ rvm use jruby-1.7.16
$ ruby -v
jruby 1.7.16 (1.9.3p203) 2012-10-22 ff1ebbe on Java HotSpot(TM) 64-Bit Server VM 1.6.0_33-b03-424-11M3720 [darwin-x86_64]

Specify JRuby in your gemfile

Once you’ve got JRuby installed locally you can add this line to your Gemfile

ruby '1.9.3', :engine => 'jruby', :engine_version => '1.7.16'

Here you are telling bundler that you intend the app to run on JRuby version 1.7.0 under compatablity mode with Ruby 1.9.3. There are going to be a few changes we will have to make to your app before we can run bundle install. Let’s take a look at them now:

Replace your server with JRuby compatible Server

Many popular Ruby server libraries rely on C bindings. There are several recommended servers on the JRuby github page. You will need one that can run your JRuby application inside of a dyno without exceeding available memory. You can use Puma the pure ruby rack server:

gem 'puma'

Also Trinidad is known to work well, though may have a slightly larger memory footprint:

gem 'trinidad'

Change Procfile

You will need to change the commands in your Procfile to start your app using the JRuby server of your choice. An example for the Puma webserver would be:

web: bundle exec rails server puma -p $PORT -e $RACK_ENV

JDBC Database Drivers

JDBC drivers for most popular databases such as Postgresql are already available for the JVM. The majority of JDBC drivers are very mature and have been heavily optimized for speed. You will need to remove the regular pg gem from your Gemfile:

gem 'pg'

And replace it with the activerecord-jdbcpostgresql-adapter

gem 'activerecord-jdbcpostgresql-adapter'

Once you have made the replacements to your Gemfile make sure you are using jruby:

$ ruby -v
jruby 1.7.16

Then run $ bundle install. If you get failures read the next section.

Replace jRuby Incompatible Gems

While many gems in the community are JRuby compatible, you may be relying on some that are not. Many gem authors choose to enable JRuby tests on TravisCI, so you could check compatibility using their most recent builds. If no records exist of whether a project will run on JRuby you can always try installing it through bundler:

$ bundle install

Or manually:

$ gem install puma

Even if a gem installs correctly there may be subtle bugs that exist in the library. It is always a good idea to run tests on your project and perform some manual testing locally to confirm compatibility.

Twitter Bootstrap

There have been reports of incompatibilities using different versions of the twitter-bootstrap-rails gem with JRuby. You may need to upgrade to a more recent version of the gem. You can find installation instructions in the twitter-bootstrap-rails README.

Deploy to Heroku

Once you’ve got your Rails project working locally on JRuby you will want to commit your code to git, spin up a new Heroku app and deploy.

$ git add .
$ git commit -m "trying out JRuby on Heroku"
$ heroku create --remote jruby-heroku

Now you can deploy by pushing to the jruby-heroku branch:

$  git push jruby-heroku master
Counting objects: 692, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (662/662), done.
Writing objects: 100% (692/692), 141.01 KiB, done.
Total 692 (delta 379), reused 0 (delta 0)

-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Using Ruby version: ruby-1.9.3-jruby-1.7.16
-----> Installing JVM: openjdk7-latest
-----> Installing dependencies using Bundler version 1.2.1
# ...

If you’ve been making your changes in a branch you can push to heroku using the my-branch:master convention. For instance if you made all your changes in a branch called jruby-experiment you could push to heroku using

$ git push jruby-heroku jruby-experiment:master

If you get any errors or warnings use the messages to debug, and try to reproduce the issue locally. If you get stuck you can ask any application specific questions on Stack Overflow.

Troubleshooting

See Specifying a Ruby Version’s troubleshooting section for some general advice.

Keep reading

  • Rails Support

Feedback

Log in to submit feedback.

Using Rack::Cache with Memcached in Rails 3.1+ (Including Rails 4) Rails 4+ Asset Pipeline on Heroku

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure
  • .NET

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • © 2025 Salesforce, Inc. All rights reserved. Various trademarks held by their respective owners. Salesforce Tower, 415 Mission Street, 3rd Floor, San Francisco, CA 94105, United States
  • heroku.com
  • Legal
  • Terms of Service
  • Privacy Information
  • Responsible Disclosure
  • Trust
  • Contact
  • Cookie Preferences
  • Your Privacy Choices