How to get project to use JRuby instead of Ruby on Windows

∥☆過路亽.° 提交于 2019-12-23 04:21:15

问题


I'm trying to stand up a JRuby/Ruby-on-Rails environment on a Windows VM. As a result, I installed Ruby, Rails and the items from the RailsInstaller download. I then installed JRuby. Everything installed and I see both when I do jruby -v and ruby -v.

How do I get my Rails project to recognize JRuby instead of Ruby? Can I achieve this without installing RVM? Should I just install RVM on the Windows VM (which I was trying to avoid, but, maybe I shouldn't)? Do I just put a line in the Gemfile?

(My very limited experience with JRuby/Ruby-on-Rails is with using RVM on a Unix environment.)

Here's my output when I do a gem env:

RubyGems Environment:
 - RUBYGEMS VERSION: 2.1.9
 - RUBY VERSION: 1.9.3 (2014-09-25 patchlevel 392) [java]
 - INSTALLATION DIRECTORY: C:/jruby-1.7.16/lib/ruby/gems/shared
 - RUBY EXECUTABLE: C:/jruby-1.7.16/bin/jruby.exe
 - EXECUTABLE DIRECTORY: C:/jruby-1.7.16/bin
 - SPEC CACHE DIRECTORY: C:/Users/user/.gem/specs
 - RUBYGEMS PLATFORMS:
   - ruby
   - universal-java-1.7
 - GEM PATHS:
    - C:/jruby-1.7.16/lib/ruby/gems/shared
    - C:/Users/user/.gem/jruby/1.9
 - GEM CONFIGURATION:
    - :update_sources => true
    - :verbose => true
    - :backtrace => false
    - :bulk_threshold => 1000
    - "install" => "--no-rdoc --no-ri --env-shebang"
    - "update" => "--no-rdoc --no-ri --env-shebang"
 - REMOTE SOURCES:
    - https://rubygems.org/
 - SHELL PATH:
    - C:\Windows\system32
    - C:\Windows
    - C:\Windows\System32\Wbem
    - C:\Windows\System32\WindowsPowerShell\v1.0\
    - c:\jruby-1.7.16\bin
    - C:\RailsInstaller\Git\cmd
    - C:\RailsInstaller\Ruby1.9.3\bin
    - C:\Program Files\jruby-1.7.16\bin

回答1:


Rails is a gem and it's installed within a Ruby installation by Rubygems, which is part of a Ruby distribution. Your path setting are set in the way, that the gem command is coming from Ruby and not from JRuby. You can remove all Ruby commands temporarily from your path, and as long as JRuby's commands are on the path it will automatically pick those.

By doing gem install bundler and bundle install you then will install Rails and all the project dependencies with JRuby.

However, that's what version managers actually do. They just switch the path settings properly. Using them simplifies the configuration of an development environment a lot. And, for Windows there is pik (RVM works only on Unix systems).



来源:https://stackoverflow.com/questions/26261334/how-to-get-project-to-use-jruby-instead-of-ruby-on-windows

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