Sunday, September 25, 2011

Setting JRuby to run in 1.9.2 mode by default

JRuby comes with both 1.8.7 and 1.9.2 (currently) and the default is 1.8.7. If you want to change it you have to feed an option at the command line:

$jruby --1.9

This weekend I had to migrate a rails program that I hadn't written and the author used 1.9.2 notation so it would not run on JRuby with the default settings. So I had to add the version option with every command which gets old quick. I looked online for a way to make this automatic (and on my JRuby books) but could only found the way to do it on a Mac or Linux but all Windows references just mentioned nebulous concepts such as environmental variables and seemed to be different from which version of Windows you are using. Here is how to do it.

Windows 7:

Got to Control Panel, System.












Wine (Crossover 10):

Java 6 version 21 will run on Wine (at least on Crossover 10) and you can install JRuby on top of that. To set environmental variables you have to go to regedit and set it there manually. Follow the screen-shots below.

Find the HKEY_CURRENT_USER option on the side bar, hit the plus sign and select "Environment" from the sub-options. Set the Key to JRUBY_OPTS (don't forget the s) and the value to --1.9 (two dashes). Then go to the right pane, right click on a white space and select "New - String Value" to create a new key. Right click on the area shown in the screen-shot. Then add a New string key with the name JRUBY_OPTS and the value --1.9 per the screen-shot.






Mac OS X and Linux:

The Mac and Linux uses a command line to set the environmental variable so it can be done with one command.

$export JRUBY_OPTS=--1.9



 

This command will set the version for the session, to make it permanent add it to your .bashrc file in your home directory.




On the mac you look for the .bash_profile file in your home directory and add the same line to it.

2 comments:

  1. Thanks for posting, this was pretty useful.

    ReplyDelete
  2. Thanks David. This post has helped me to run Jruby in 2.0 mode on Windows.

    ReplyDelete