Appendix B. JRuby

 

JRuby is an implementation of the Ruby language that runs on the Java Virtual Machine (JVM). The main benefits of using JRuby are the ability to mix Ruby and Java code, the performance benefits gained from running on the JVM, and the ability to deploy web applications to Java servers like Tomcat and J2EE. This appendix provides an overview that will help you get started exploring the many facets of JRuby.

B.1. Installing and using JRuby

The steps required to install JRuby are the same on all operating systems. First, make sure you have Java installed and that the java command is accessible from the path. Next, download the most recent version of JRuby available from dist.codehaus.org/jruby, expand the archive to a directory of your choice, and set the path to point to the bin directory that contains the various JRuby executables (jruby, jirb, etc.). Verify that JRuby is installed correctly by running jruby --version from the command line.

For example, on Linux you could download and install JRuby 1.1.2 like this:

$ curl -OL http://dist.codehaus.org/jruby/jruby-bin-1.1.2.tar.gz
$ tar -xz < jruby-bin-1.1.2.tar.gz
$ mv jruby-1.1.2 /opt/jruby
$ echo "export PATH=\$PATH:/opt/jruby/bin" >> .profile

To run Ruby programs using JRuby, use the jruby command:

$ jruby myprog.rb

You can also use jirb, the JRuby Interactive Interpreter, the same way you would use irb (see appendix A for instructions on how to install Wirble).

B.2. JRuby and Ruby side by side

B.3. Mixing Ruby and Java

B.4. Scripting with Ruby

B.5. Deploying web applications