A different rubygem version for each ruby version in rvm - ruby

I have ruby 1.8.7 and 1.9.3 installed by rvm. For each ruby version, I'd like to:
use gem 1.3.7 for ruby 1.8.7
use gem 1.8.x for ruby 1.9.3
How can I set the above in rvm?

$ rvm use 1.8.7
$ rvm rubygems 1.3.7
$ rvm use 1.9.3
$ rvm rubygems latest-1.8
$ gem -v
1.8.24
$ rvm use 1.8.7
$ gem -v
1.3.7

When install rvm and then rvm install ruby --version its taken latest rubygems version. So just follow the below steps:
rvm use 1.8.7
gem -v, e.g. shows 1.8.24 like that
If you want to use rubygems particular version only follow steps #3 and #4.
This is for syntax set the rubygems in rvm
rvm rubygems [x.y.z|latest-x.y|latest|remove]
Ex like this:
Retrieving rubygems-1.3.7
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 284k 100 284k 0 0 94166 0 0:00:03 0:00:03 --:--:-- 125k
Extracting rubygems-1.3.7 ...
Removing old Rubygems files...
Installing rubygems-1.3.7 for ruby-1.8.7-p371 ...
Installation of rubygems completed successfully.
then
gem -v => It shows 1.3.7
rvm rubygems 1.3.7
And If you want use any other version go to step #3
Ex: rvm rubygems latest

If you have already created gemsets in rvm for 1.3.7 and 1.8.x, skip this step. Otherwise, you need to create the gemset.
Here is how to create a gemset and then switch to it:
rvm 1.8.7 # switch to ruby 1.8.7
rvm gemset create 1.3.7 # you may have to do it this way: rvm --force rubygems 1.3.7
rvm gemset use 1.3.7 # use it
Next time you want to use ruby 1.8.7 with gemset 1.3.7 you only need to do this:
rvm use 1.8.7#1.3.7 # this sets the ruby version and gem version
ruby -v # checks the ruby version, should = 1.8.7
gem --version # checks the gemset version, should = 1.3.7
Repeat this for ruby 1.9.3 and gemset 1.8.x.
You can find out how to do this and find answers to questions other rvm related topics here: http://rvm.io/gemsets/using

Related

Ruby RVM gives me version 2.0 but Bundler says I'm incorrectly running version 2.3

I am just starting to work on an old Ruby Rails project. The Gemfile specifies:
ruby '2.0.0'
I am running a new version of Ubuntu, which I think came with Ruby 2.3 as the default. So I install RVM and then I:
rvm --default use 2.0.0
ruby -v
which gives me:
ruby 2.0.0p648 (2015-12-16 revision 53162) [x86_64-linux]
then I run:
bundle install
and I get this error:
Your Ruby version is 2.3.1, but your Gemfile specified 2.0.0
How do I get RVM to enforce the correct version of Ruby?

I can't install the first version of any Ruby with RVM

When I try to install the 1.8.7 version of Ruby:
rvm install 1.8.7
He actually install Ruby 1.8.7-head (1.8.7 patchlevel 376).
How can I install the real first version (http://cache.ruby-lang.org/pub/ruby/1.8/ruby-1.8.7.tar.gz)?
Try this:
rvm install 1.8.7 -l 0
or
rvm install 1.8.7-p0
RVM is installing the latest patchlevel by default, so you need to specify the patchlevel that you want.

gem installed in directory of different patchlevel

After updating from ruby-1.8.7-p352 to ruby-1.8.7-p358 via rvm, gems are still installed to the path of ruby-1.8.7-p352.
$GEM_PATH is set correctly but rvm gemdir is wrong.
# rvm use ruby-1.8.7-p358
Using /usr/local/rvm/gems/ruby-1.8.7-p358
# ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
# echo $GEM_PATH
/usr/local/rvm/gems/ruby-1.8.7-p358:/usr/local/rvm/gems/ruby-1.8.7-p358#global
# rvm gemdir
/usr/local/rvm/gems/ruby-1.8.7-p352
Installing gems works without errors but the location of the gem is wrong and binaries can't be executed.
# gem instll bundler
Successfully installed bundler-1.1.3
1 gem installed
# bundle
bash: bundle: command not found
# which bundle
/usr/bin/which: no bundle in (/usr/local/rvm/gems/ruby-1.8.7-p358/bin:/usr/local/rvm/gems/ruby-1.8.7-p358#global/bin:/usr/local/rvm/rubies/ruby-1.8.7-p358/bin:/usr/local/rvm/bin:/usr/local/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
# gem which bundler
/usr/local/rvm/gems/ruby-1.8.7-p352/gems/bundler-1.1.3/lib/bundler
I tried export GEM_HOME=/usr/local/rvm/gems/ruby-1.8.7-p358 but rvm gemdir still shows the path to p358 and gems are installed to this path.
Updating the rubygems solved the problem:
# rvm rubygems latest

how to install rubygems-1.4.2 to ruby 1.8.7 using rvm?

When I do ruby -v, I get
ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-linux]
I want to install rubygems-1.4.2 to it, but the command:
rvm rubygems 1.4.2
fails, it does not even fetch the rubygems as it fails in curl. So I downloaded the file from http://rubyforge.org/frs/?group_id=126, (http://rubyforge.org/frs/download.php/73882/rubygems-1.4.2.tgz), extracted it, and put it at ~/.rvm/src/, and then ran again:
rvm rubygems 1.4.2
but it failed again. how can i install rubygems 1.4.2 to ruby-1.8.7#p330?
First switch to the correct ruby with rvm use 1.8.7#p330, then
gem install rubygems --version=1.4.2

How do you update rubygems using rvm and ree?

How do you update rubygems under rvm when ree is your default vm (on Snow Leopard)? I am doing:
$ rvm ree gem update --system
This results in things looking like everything went fine:
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.3.7
Updating RubyGems to 1.3.7
Installing RubyGems 1.3.7
RubyGems 1.3.7 installed
[...]
RubyGems installed the following executables:
/Users/douglassellers/.rvm/rubies/ree-1.8.7-2010.02/bin/gem
but when I run gem --version it still says 1.3.5. Doing a which gem points at ree version of gem.
Anyone know how to get rubygems to update with RVM?
Now you can just do :
rvm rubygems latest
Or you can define which rubygems you really want. https://rvm.io/rubies/rubygems/
The problem, I think, is the initial command (or what you expect that command to do):
$ rvm ree gem update --system
That tells rvm to pass the gem update --system to the gem under ree, but it doesn't switch you to that particular Ruby interpreter. You continue using whatever interpreter you have set in that shell (whether by default or because you switched manually earlier in the shell session).
As an example, my default interpreter is Ruby 1.9.2. If I pass this command: rvm 1.9.1 gem install pony, then the Pony gem is installed for Ruby 1.9.1. However, I'm still using Ruby 1.9.2 after that installation is finished. If I enter irb and try require 'pony', I get a load error. If I run rvm 1.9.1 and then enter irb, Pony is installed and loads fine.
So as Brian says in his comment to your post, you could switch manually with rvm use ree. Alternatively, you could switch your initial command to this:
$ rvm ree
$ gem update --system
$ gem --version
rvm suggested me to use something like this:
rvm ruby-1.9.3-p327#mygemset do gem update --system
It is an unusual problem.
If it is not yet resolved, consider using
rvm --default use ree
which ruby
which gem
this should show you if you are in the right version.
install gems either using rvm or directly.

Resources