How to make JRuby 1.6 default to Ruby 1.9?

倖福魔咒の 提交于 2019-11-27 10:13:22

Use the JRUBY_OPTS environment variable. JRUBY_OPTS holds a list of arguments that are added to any arguments specified on the command line.

For example (on Linux):

$ jruby -v
jruby 1.6.0.RC1 (ruby 1.8.7 patchlevel 330) (2011-01-10 769f847) (Java HotSp...
$ export JRUBY_OPTS=--1.9
$ jruby -v
jruby 1.6.0.RC1 (ruby 1.9.2 trunk 136) (2011-01-10 769f847) (Java HotSpot(TM...
$ export JRUBY_OPTS=--1.8
$ jruby -v
jruby 1.6.0.RC1 (ruby 1.8.7 patchlevel 330) (2011-01-10 769f847) (Java HotSpo...

An alternative solution is to put the following line (and other settings) in your ~/.jrubyrc file

compat.version=1.9

RVM allows now building JRuby/Rubinius with default mode set by default:

rvm install jruby-1.6.7-d19 --1.9
rvm install rbx-2.0.testing-d19 --1.9

The suffix -d19 can be omitted, I use it only to distinguish between 1.8 and 1.9 mode rubies.

The --1.9 mode will become the default in next major releases of JRuby/Rubinius, so you can make sure you will use 1.8 with --1.8 rvm switch.

UPDATE 2012-05-25: Jruby 1.7.0.preview1 is out, it is 1.9 by default!

taiansu

In Windows, use set JRUBY_OPTS=--1.9 instead.

When using warbler to package an app as a war file, the version can be set by running:

warble config

which creates a config/warble.rb file. This file contains lots of comments on how to configure warbler, and in particular:

  # Set JRuby to run in 1.9 mode.
  # config.webxml.jruby.compat.version = "1.9"

Uncomment the second line by removing the #, and re-package your war with the warble command.

If you're creating jruby from java:

RubyInstanceConfig config = new RubyInstanceConfig();   
config.setCompatVersion(CompatVersion.Ruby1_9); 
Ruby runtime = Ruby.newInstance(config)

(Thanks to bbrowning on the #jrubyc irc channel)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!