aboltart
aboltart

Reputation: 171

How to set correct value for JRUBY_HOME if I am using rbenv

I installed JRuby with rbenv

ruby -v
jruby 1.6.7.2 (ruby-1.9.2-p312) (2012-05-01 26e08ba) (Java HotSpot(TM) 64-Bit Server VM 1.7.0_01) [linux-amd64-java]

which ruby
~/.rbenv/shims/ruby

gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.8.24
  - RUBY VERSION: 1.9.2 (2012-05-01 patchlevel 312) [java]
  - INSTALLATION DIRECTORY: /home/myjava_api/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8
  - RUBY EXECUTABLE: /home/myjava_api/.rbenv/versions/jruby-1.6.7.2/bin/jruby
  - EXECUTABLE DIRECTORY: /home/myjava_api/.rbenv/versions/jruby-1.6.7.2/bin
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-java-1.7
  - GEM PATHS:
     - /home/myjava_api/.rbenv/versions/jruby-1.6.7.2/lib/ruby/gems/1.8
     - /home/myjava_api/.gem/jruby/1.9
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :benchmark => false
     - :backtrace => false
     - :bulk_threshold => 1000
     - "install" => "--no-rdoc --no-ri"
     - "update" => "--no-rdoc --no-ri"
  - REMOTE SOURCES:
     - http://rubygems.org/

But $JRUBY_HOME is not set

When I set $JRUBY_HOME to "/home/myjava_api/.rbenv/versions/jruby-1.6.7.2/bin/jruby" and after re-login when I executed "ruby -v" I got error: "Error: Could not find or load main class org.jruby.Main"

When I remove $JRUBY_HOME variable "ruby -v" works fine

What must be correct $JRUBY_HOME value?

Upvotes: 1

Views: 7140

Answers (3)

Edub Kendo
Edub Kendo

Reputation: 473

I was trying out this tool (rbenv) after managing my PATH by hand for a while, for the first time and got this same error: Error: Could not find or load main class org.jruby.Main I had completely forgotten to unset the old JRUBY_HOME setting in my .bash_rc file, after uninstalling my previous version of jruby to try out rbenv.

In response to the other answers, I have certain tools and libraries that require the JRUBY_HOME variable to be set in order to work, http://vertx.io/ is one example. On the other hand, a number of gems and tools these days go the other route, and seem to assume that you are using either rvm or rbenv. So using one of those tools, but continuing to set JRUBY_HOME seems to be the path of least resistance.

Fortunately, when JRUBY_HOME is set correctly, it will work just fine with rbenv. For instance, mine is set like this export JRUBY_HOME="/home/user/.rbenv/versions/jruby-1.7.1"

The original poster's error appears to be trying to set the variable to the jruby executable, when in fact JRUBY_HOME should simply be the entire jruby directory. I think his should be "/home/myjava_api/.rbenv/versions/jruby-1.6.7.2". Hope that clears things up. I realize this is an old question, but when I searched the error, it was the first relevant result.

Upvotes: 3

The whole point of utilities like rbenv or rvm is to be able to switch between ruby implementations without worrying about changing environment variables, as they do it for you; you shouldn’t need to set $JRUBY_HOMEto run JRuby (which incidentally for you would be /home/myjava_api/.rbenv/versions/jruby-1.6.7.2) as these utilities are aimed to make the underlying implementation transparent.

Upvotes: 2

user1434691
user1434691

Reputation: 19

I guess the obvious question is why do you want $RUBY_HOME if it works fine without it?

JRuby is so simple to install you don't need any version manager. Just download the Zip file and extract it to any directory you like. Then add the JRuby/bin directory to your path. In your case that would seem to be /home/myjava_api/.rbenv/versions/jruby-1.6.7.2/bin.

If you have several projects that require different versions of JRuby or different groups of gems just extract a copy of the appropriate JRuby version for each project. Assuming you use the correct PATH for each project the correct version of JRuby will run and it will have all the gems you installed for that project, and each project will be quite separate.

Upvotes: 1

Related Questions