It seems that the idiomatic way to provide flags to JRuby in an RVM-based Rails project is to set the environmental variable JRUBY_OPTS or PROJECT_JRUBY_OPTS, the latter perhaps being done automatically, since I see I can uncomment this line from my project directory's .rvmrc
:
PROJECT_JRUBY_OPTS=( --1.9 )
However, that line seems to do nothing, and if I set the environmental variables, RVM actually unsets them.
So, how am I supposed to do this?
(Note that I have this at the bottom of my .bashrc file, which is how I believe I'm supposed to use rvm:)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.
Example:
$ JRUBY_OPTS=--1.9 jruby -v
jruby 1.6.5 (ruby-1.9.2-p136) (2011-10-25 9dcd388) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_27) [darwin-x86_64-java]
$ export JRUBY_OPTS=--1.9
$ jruby -v
jruby 1.6.5 (ruby-1.8.7-p330) (2011-10-25 9dcd388) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_27) [darwin-x86_64-java]
$ env | grep JRUBY_OPTS
[empty result]
I put
export JRUBY_OPTS="..."
in my project's.rvmrc
, at the bottom of the file. This works for me.Add this line to your .bashrc file
It's working fine for me
this option was parsed with jruby nailgun hook only, i have added a new hook to parse only this options (no ng):
and it should work upon entering directory with this option
Since your are using rvm just create a file .ruby-env in your directory folder. Inside the file you can define your custom env. Like:
@mpapis identified the problem and provided the fix. Here's some additional background. TL;DR: use
PROJECT_JRUBY_OPTS
and the jRuby hooks.jRuby uses
JRUBY_OPTS
to configure jRuby's behavior.RVM supports
PROJECT_JRUBY_OPTS
with two provided hook files (currently,after_use_jruby
andafter_use_jruby_opts
). If enabled by making them executable, the hooks use the script library functionsjruby_options_append
andjruby_options_remove
to append/remove the options inPROJECT_JRUBY_OPTS
to/fromJRUBY_OPTS
.So, you have two options.
If you install the latest RVM, you can roll your own per-project .rvmrc, and you can set environment variables and run commands, as you would expect. No additional steps are required.
And then:
Or you can enable the jruby hooks, generate an .rvmrc, and customize it:
Then:
And now:
There are subtle differences to the two approaches.
With the first approach, the changes to
JRUBY_OPTS
persist even if you navigate back out of the project directory. With the second approach, the project-specific options are removed from theJRUBY_OPTS
environment variable when you navigate out of the project directory.Likewise, the first case overwrites
JRUBY_OPTS
with the value in .rvmrc, while the second case intelligently appends the project-specific information.@paul-biggar, unfortunately I wasn't able to duplicate the problem where RVM unset
JRUBY_OPTS
.