How to get project to use JRuby instead of Ruby on Windows - ruby-on-rails

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

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).

Related

MacOS: Ruby LoadError when trying to install Rails

I've already tried Googling everything; don't just point me towards the first few results you get when Google searching the same error.
This is what I've tried:
ruby 2.0 rails gem install error "cannot load such file -- openssl".
When I try to do gem install rails, I get this error. Frankly it happens when I try to gem install anything.
ERROR: Loading command: install (LoadError)
cannot load such file -- openssl
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
Also, I should have Ruby 2.7.1 installed (I've installed it multiple times with brew, rbenv, and rvm), but when I do ruby -v it always returns ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]. I read somewhere that any Ruby version < 2.4 isn't compatible with OpenSSL 1.1. I need Ruby > 2.4.4 to install rails.
Here's my gem env
[14:21:23] jasper.huang ruby-2.7.1 gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.1.2
- RUBY VERSION: 2.7.1 (2020-03-31 patchlevel 83) [x86_64-darwin18]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.7.0
- USER INSTALLATION DIRECTORY: /Users/jasper.huang/.gem/ruby/2.7.0
- RUBY EXECUTABLE: /usr/local/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /usr/local/bin
- SPEC CACHE DIRECTORY: /Users/jasper.huang/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /usr/local/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-18
- GEM PATHS:
- /usr/local/lib/ruby/gems/2.7.0
- /Users/jasper.huang/.gem/ruby/2.7.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/jasper.huang/Documents/School/USC/SPRING20/CSCI310/Project2/google-cloud-sdk/bin
- /Library/Frameworks/Python.framework/Versions/3.7/bin
- /usr/local/CrossPack-AVR/bin
- /Library/Frameworks/Python.framework/Versions/3.5/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/share/dotnet
- /opt/X11/bin
- ~/.dotnet/tools
- /Library/Frameworks/Mono.framework/Versions/Current/Commands
- /usr/local/CrossPack-AVR/bin
- /Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin
- /Users/jasper.huang/.rvm/bin
I recently faced this issue and the problem was that ruby command was using core default ruby installation (i.e 2.3) instead of rvm ruby version. I am not sure how this happened but I faced this issue after I installed 'ohmyzsh' plugin. This is again a guess and I am not 100% sure if this plugin caused this issue.
So, I had to uninstall the plugin and re installed rvm and openssl package. Than, install the ruby version with openssl directory as parameter as suggested in the link you have shared.
You can also use the system installed openssl directory as well. Also try using this parameter while installing the gem '-- --with-opt-dir=/usr/local/opt/openssl'. The path should the openssl installed directory on your machine.
You need to make sure that you have rvm and ruby is installed and working fine by checking the ruby installed in rvm is activated in your machine. I hope this helps and please let me know if you have any further queries. Thank you.

Running Ruby with Homebrew but cannot get Bundler to Work

Running bundle install I get the error: "-bash: bundle: command not found"
I can install Bundler with gem install bundler and I get no errors. In fact, if I run gem list it shows bundler (1.14.6). However, bundle -v or anything like that doesn't work.
I have uninstalled bundler and re-installed.
gem env returns:
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.5.1
- RUBY VERSION: 2.2.3 (2015-08-18 patchlevel 173) [x86_64-darwin15]
- INSTALLATION DIRECTORY: /usr/local/Cellar/ruby/2.2.3/lib/ruby/gems/2.2.0
- RUBY EXECUTABLE: /usr/local/Cellar/ruby/2.2.3/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/Cellar/ruby/2.2.3/bin
- SPEC CACHE DIRECTORY: /Users/mike/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /usr/local/Cellar/ruby/2.2.3/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-15
- GEM PATHS:
- /usr/local/Cellar/ruby/2.2.3/lib/ruby/gems/2.2.0
- /Users/mike/.gem/ruby/2.2.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/Cellar/ruby/2.2.3/bin/ruby
- /usr/local/bin/gem
brew doctor says "Your system is ready to brew"
echo $PATH says /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/Cellar/ruby/2.2.3/bin/ruby:/usr/local/bin/gem
which gem returns: /usr/local/bin/gem
While this may not be a solution to your current issue, it is an alternative that could help you down the road in developing in Ruby / Rails.
I'd recommend moving to a ruby version control system such as RVM or rbenv where you then have full control over your ruby version on a per-project basis. It's much easier than playing with your system Ruby on OS X too. You'll probably find that once you have one of these installed, your bundler issues disappear.
Well, it's a little bit late answer, but I was able to do it like this:
gem install bundler -n /opt/homebrew/opt/ruby#2.5/bin
Where /opt/homebrew/opt/ruby#2.5/bin is a path where homebrew ruby installation gems is located

RubyGems environment variables messed up :(

Please see below the print out from gem env. It appears as the INSTALLATION DIRECTORY, USER INSTALLATION DIRECTORY and GEM PATHS are screwed up. I attempted to install ruby version 2.3.0 for another project and switch over to that. I uninstalled ruby version 2.3.0 and switch back to ruby version 2.3.1. I noticed these RubyGems environment variables got screwed up some how :( Everywhere you see '2.3.0', I think it's wrong.
RubyGems Environment:
- RUBYGEMS VERSION: 2.5.1
- RUBY VERSION: 2.3.1 (2016-04-26 patchlevel 112) [x86_64-darwin15]
- INSTALLATION DIRECTORY: /Users/matthewsmith/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- USER INSTALLATION DIRECTORY: /Users/matthewsmith/.gem/ruby/2.3.0
- RUBY EXECUTABLE: /Users/matthewsmith/.rbenv/versions/2.3.1/bin/ruby
- EXECUTABLE DIRECTORY: /Users/matthewsmith/.rbenv/versions/2.3.1/bin
- SPEC CACHE DIRECTORY: /Users/matthewsmith/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/matthewsmith/.rbenv/versions/2.3.1/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-15
- GEM PATHS:
- /Users/matthewsmith/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
- /Users/matthewsmith/.gem/ruby/2.3.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/matthewsmith/.rbenv/versions/2.3.1/bin
- /Users/matthewsmith/.rbenv/libexec
- /Users/matthewsmith/.rbenv/plugins/ruby-build/bin
- /Users/matthewsmith/.nvm/versions/node/v4.5.0/bin
- /Users/matthewsmith/.rbenv/shims
- /Users/matthewsmith/.rbenv/bin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
if there are multiple versions installed, project dependent version must be set as default.
To handle multiple projects with different dependencies, gemset can be used. RVM support gemset. Alternatives are available for rbenv also.
Nothing is wrong. I can see that you are using rbenv, and that your global ruby version is 2.3.1
If you run in your terminal:
gem env home
It will return something like:
/Users/matthewsmith/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0
Apparently this line of code above tells that you have global rbenv version 2.3.1, and within li/ruby/gems folder you also have installed ruby version 2.3.0
In this folder .rbenv/versions/ will be all ruby versions you will about to install, or they are already installed.
When I install different ruby version let's say 2.3.0 I would do like this:
rbenv install 2.3.0 # install ruby version 2.3.0 using rbenv
rbenv local 2.3.0 # set ruby 2.3.0 to local project. It writes that version to a .ruby-version in your current directory
ruby -v # check your version to confirm that is 2.3.0 for a local project
gem install bundler
bundle install
Other options for installing ruby version are: SHELL and GLOBAL
rbenv shell 2.3.0 # Will temporarily change your Ruby version on your current shell. This sets the RBENV_VERSION environment variable in your terminal session.
rbenv global 2.3.1 # This will also change your Ruby version, but only the one you are using whenever no other version is specified, e.g. via a .ruby-version file or RBENV_VERSION variable.
NOTE! You don't need sudo to install gems. Typically, the Ruby versions will be installed and writeable by your user. No extra privileges are required to install gems.
reference
I hope it helps

How to change the path where ruby gems are installed on OS 10.6.6 Ruby 1.8 and Rails 3

Whether I use gem install or bundle install for my gems, they don't work. Sometimes sudo gem install gets gems to work. I ran the gem list -d and which gem commands, and it seems that my system is configured such that all the gems get installed into " /Library/Ruby/Gems/1.8" but my environment expects them in "/usr/bin/gem". How could I properly correct this? I was under the impression that 'bundle' should be able to install a local, application specific copy of a gem?
Although many Rubyists will recommend you RVM or RBENV, I do not use it. It's VERY slow and it pollutes your environment.
If you use Bundler, you dont need RVM at all - rubygem itself supports multiple versions of single gems. So you can just start using gems (e.g. gem install etc) and it will install into your $HOME/.gem directory by default. You can check the installation path using:
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.25
- RUBY VERSION: 1.9.3 (2013-02-06 patchlevel 385) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/lzap/.gem/ruby/1.9.3
- RUBY EXECUTABLE: /usr/bin/ruby
- EXECUTABLE DIRECTORY: /home/lzap/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/lzap/.gem/ruby/1.9.3
- /usr/share/gems
- /usr/local/share/gems
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "install" => "--no-rdoc --no-ri"
- REMOTE SOURCES:
- http://rubygems.org/
You can even change this with GEM_HOME environment variable. Happy gemming!
I would suggest using RVM (Ruby Version Manager) to control which version of Ruby you are installing your gems into. It will also help keep all the bundle and gem data in a folder in your home directory.

Multiple rubygems versions

Basically what I need is to install rubygems 1.3.5 on a machine (Debian) with 1.2.0 installed and having no root access.
What I've done so far: installed rubygems into $HOME/rubygems and set up GEM_HOME + added bin to the path. So running "which gem" shows me the new binary, not the old one. Also when I gem install something, it installs correctly into the new repository.
However, gem -v gives 1.2.0. And gem env gives the following:
RubyGems Environment:
- RUBYGEMS VERSION: 1.2.0
- RUBY VERSION: 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
- INSTALLATION DIRECTORY: /home/neutrino/rubygems/gems
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /home/neutrino/rubygems/gems/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/neutrino/rubygems/gems
- /var/lib/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gemhome" => "/home/neutrino/rubygems/gems"
- REMOTE SOURCES:
- http://gems.rubyforge.org/
Any hints will be appreciated. I just can't see what I'm doing wrong.
I expect that the problem will be related to the gem command finding the 1.2.0 version of RubyGems from the system lib paths ahead of your local version.
You could try setting the RUBYLIB environment variable to the directory containing the rubygems.rb file. The contents of RUBYLIB (colon delimited directories) gets prepended to the Ruby load path at startup.
It sounds like you need to take a look at rvm, especially its ability to have multiple gem sets.
http://rvm.io/
http://rvm.io/gemsets/
You need to put $HOME/rubygems/bin in your PATH environment before /usr/bin/.
If that's not doable I would rename $HOME/rubygems/bin/gem to $HOME/rubygems/bin/my_gem and do my_gem -v and continue using it that way(my_gem)

Resources