Multiple rubygems versions - ruby-on-rails

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)

Related

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

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

RVM gem permissions error

I started trying to set up a local rails installation for development. After I installed in using apt-get, however, I learned about RVM, so I removed the earlier one, and reinstalled from RVM. It looks like I have residual problems, though. Specifically, when I try to install rails I get...
$ gem install rails
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /var/lib/gems/1.9.1 directory.
This already looks like a problem, because I don't want it to be in the /var/ directory, I want it to be in the user directory. So, I check the following...
$ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.11
- RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /var/lib/gems/1.9.1
- /home/myusername/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
As well as sudo'd:
$ sudo gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.11
- RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /var/lib/gems/1.9.1
- /home/myusername/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
gems seem to live in /var/lib for some reason. Is this normal? How can I fix this so I can install the rails gem?
EDIT: UPDATE!
It appears to me that I have gems installed twice, once in /var/lib/gems/1.9.91 (bad) and once in /home/myusername/.gem/ruby/1.9.1 (good).
I think what is happening here is that when I type "gem" the installation in /var/lib/gems/1.9.1 (bad) is taking priority over /home/myusername/.gem/ruby/1.9.1 (good). Can anyone confirm that? Also, would it be OK and fix things just to delete the bad directory, or would that cause problems?
You missed to use ruby, you can do it with:
rvm use 1.9.3 --install
In case 1.9.3 was not installed, this command will also install it!
It also looks you are using Ubuntu, make sure you are not using RVM from Ubuntu package - that thing is broken! You can find instruction how to fix it here: https://stackoverflow.com/a/9056395/497756

How to Understand My Ruby Environment in Ubuntu?

I am having some path issues and trying to understand how to read and match the paths. Here is what I am doing:
$PATH
bash: /home/agenadinik/.rvm/gems/ruby-1.9.2-p180/bin:/home/agenadinik/.rvm/gems/ruby-1.9.2-p180#global/bin:/home/agenadinik/.rvm/rubies/ruby-1.9.2-p180/bin:/home/agenadinik/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: No such file or directory
And then I am trying to see what is in my ruby environment:
$gem environment
/home/agenadinik/.rvm/rubies/ruby-1.9.2-p180/bin/gem:4:
RubyGems Environment:
- RUBYGEMS VERSION: 1.6.2
- RUBY VERSION: 1.9.2 (2011-02-18 patchlevel 180) [i686-linux]
- INSTALLATION DIRECTORY: /home/agenadinik/.rvm/gems/ruby-1.9.2-p180
- RUBY EXECUTABLE: /home/agenadinik/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
- EXECUTABLE DIRECTORY: /home/agenadinik/.rvm/gems/ruby-1.9.2-p180/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/agenadinik/.rvm/gems/ruby-1.9.2-p180
- /home/agenadinik/.rvm/gems/ruby-1.9.2-p180#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
What I don't understand is which of my paths need to be matched up in my ruby environment and the $PATH
Also, is my $PATH pretty much what is set in my /home/username/.bashrc file?
What is usually the path of the Ruby executable that I need to point to?
Also, doing which ruby returns this:
$ which ruby
/home/agenadinik/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
Thanks!!
You are using RVM. You have many available Ruby paths. When you source the RVM scripts in your bashrc it will modify your path. Every time you rvm use XXX it will modify your path to reflect the new version of Ruby and update all of the bins to match that version. If you are trying to make a proper shebang for a Ruby script you should use env.
#!/usr/bin/env ruby
This will find the current ruby executable in your path.

Installing ruby executables via bundler puts them in a different location than gem install

Having some issues installing a gemset in ruby 1.8.7p334 (enterprise edition) running rails 1.2.6 on Fedora 8.
The main issue I have is that bundler installs the executables in /usr/lib/ruby/gems/1.8/bin. However, Gem installs the executables in /usr/bin, which is where I want them.
How can I tell bundler to place them in /usr/bin? I've looked at the --binstubs flag, but it doesn't seem to complete the necessary requirements.
Any help is much appreciated.
RubyGems Environment:
- RUBYGEMS VERSION: 1.5.2
- RUBY VERSION: 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.8
- /root/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
Of course I find the answer after posting the question. It's the little-documented BUNDLE_BIN configuration key. It can be set by .bundle/config, an environment variable (my choice) or by bundle config. Looks like you can also specify it on the command line as --bin.
$ export BUNDLE_BIN="/usr/bin"
bin (BUNDLE_BIN)
Install executables from gems in the bundle to the specified directory.
Defaults to false.

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.

Resources