Getting up and running with jruby, MySQL and the Rails 3 beta
February 16, 2010
This is a quick recipe to get the Rails 3 Beta to run with jruby and MySQL.
Start by installing the dependencies for rails:
jruby -S gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n
jruby -S gem install rails --pre
You might have to make sure the version of rack-mount is not too recent for rails - on my Mac Rails wouldn’t use the installed version:
jruby -S gem install rack-mount --version=0.4.7
Now you should be able to create the app:
jruby -S rails rails_3_app
cd rails_3_app
Modify the Gemfile to work with jdbc:
Replace:
gem "sqlite3-ruby", :require => "sqlite3"
With:
gem "activerecord-jdbc-adapter", '0.9.3', :require =>'jdbc_adapter' if defined?(JRUBY_VERSION)
At this moment activerecord-jdbc-adapter 0.9.3 still hasn’t been pushed to Gemcutter, and the current version is not compatible with rails 3 - so you might have to install it manually:
download http://mojo.saumya.de/rubygems/activerecord-jdbc-adapter/0.9.3/activerecord-jdbc-adapter-0.9.3-java.gem and run:
jruby -S gem install activerecord-jdbc-adapter-0.9.3-java.gem
Now it’s time to get the bundler going:
jruby -S bundle install
This should prepare all the gems necessary for running the rails 3 app. Now configure your database.yml:
Prepare jdbc and configure mysql as usually in database.yml:
jruby script/rails generate jdbc
That’s it - Rails should be ready and you can proceed as usual…
Posted by Mathias Biilmann. Category: Ruby. Tags: jruby rails mysql.
Posting Comment...
Charles Oliver Nutter said 6 months ago:
I had to remove the two activerecord-jdbcXXXX-adapter lines from my gemfile and just have the main activerecord-jdbc-adapter plus the driver I used; activating the jdbcXXXX-adapter gems wanted to pull in AR-JDBC 0.9.2 instead of 0.9.3.
But yeah, it's working! Thanks for this write-up!
Mathias Biilmann said 6 months ago:
Here they don't give any problems, but they are also not needed so I'll remove them from the instructions. Thanks!
John Woodell said 6 months ago:
$ jruby -S gem install rails --pre ERROR: Error installing rails: actionpack requires rack-mount (~> 0.4.0, runtime) $ jruby -S gem list | grep rack-mount rack-mount (0.5.1)
Mathias Biilmann said 6 months ago:
Try if doing:
jruby -S gem install rack-mount --version=0.4.7
Solves it
Phil Suh said 2 months ago:
really, helpful, thank you.