In the wake of our recent announcement of JRuby support, we have a guest post from Charlie Nutter of the JRuby team on getting starting with JRuby:
“Last week, Engine Yard announced they would soon support running JRuby in their cloud environment. I think I speak for the whole JRuby community when I say how excited we are about this new possibility. JRuby has proven itself a top-notch, production-quality Ruby implementation, and the Engine Yard announcement really made us feel proud of what we’ve accomplished. It also got us thinking about what JRuby really means for Engine Yard customers.
JRuby is, simply put, Ruby on top of the Java virtual machine. While this means you get the benefits of the JVM’s world-class garbage collectors, libraries, and optimizations, it does not mean you have to know Java to use JRuby. We’ve worked very hard to make JRuby look and feel “just like Ruby.” So much so, that these days basically all pure-Ruby libraries should “just work” out of the box. Rails runs great, and there’s dozens of production users out there reaping the benefits of JRuby’s outstanding memory management, native threads (actually running in parallel!), and excellent performance…all of which we continue to improve with every release. JRuby at Engine Yard means you’ll also be able to take advantage of Engine Yard Ruby and Rails expertise, along with the assurances that your application will “just work” in their cloud.
So how do you get started with JRuby? Easy!
- Download JRuby from http://www.jruby.org. JRuby 1.3.0 is the current release, but you can feel comfortable testing out either 1.3.0 or 1.2.0: the previous release several folks already have in production.
- Unpack it somewhere convenient. You don’t have to install it as root, but you can if you like. And you can have as many separate JRuby installs as you want, alongside any standard Ruby installs already on your system.
- Put JRuby’s “bin” directory somewhere in your PATH, so you can run the “jruby” command easily.
That’s it! You’re ready to try it out!
Depending on how you have your PATH set up, you can either run “gem” to install RubyGems (if JRuby’s “gem” comes earlier in the path than standard Ruby), or you can run “jruby -S gem” to force JRuby’s copy to run (this will work for anything else in JRuby’s bin dir, too). A few gems you’ll probably want to know about:
- Rails works great! Just “gem install rails” or “jruby -S gem install rails” and you’re nearly there.
- ActiveRecord is also well-supported in JRuby, but you’ll need to install the JDBC-based (Java’s DB API) adapters. So for mysql, you want “gem install activerecord-jdbcmysql-adapter” and “jdbcmysql” as your adapter type in database.yml. For sqlite3 there’s “activerecord-jdbcsqlite3-adapter”, and so on.
- Gems that have native extensions (C code, usually indicated by RubyGems trying to build something on install) will not work in JRuby. Usually there’s an equivalent library, either a port of the C version, a wrapper around the actual C library, or a Java version. jruby.org provides a good list of commonly-used extensions and their equivalents on JRuby, or you can check isitjruby.org to see if your favorite extension is supported or has an alternative.
We’ll be publishing more information about how to get up and running with JRuby, especially if you have native dependencies, over the next couple weeks. And of course you can join the JRuby mailing lists or visit our IRC channel #jruby on FreeNode any time. There’s never been a better time to try JRuby!”