How to “activate” another version of a particular gem?

I want to switch between rails 2.3.10 as an "active" gem for my OS so that I can call it on the command line.

Can this be done? I do not use rvm. Maybe it's time to start.

I tried gem install rails --version=2.3.10 , but this only ensures that the gem version is installed, it does not fit in /usr/bin/rails .

(I already use bundler for my applications, but still did not need precise control of gems at the OS level)

+72
ruby ruby-on-rails rubygems rvm
Dec 07 '10 at 3:29
source share
4 answers

If your problem is to run executables of a certain version, then:

 rails --version # => the latest version rails _2.3.10_ --version # => Rails 2.3.10 

This template ( gem-binary _gem-version_ ) works for any gem binary.

Hope this helps.

+133
Dec 07 '10 at 4:44
source share

Use RVM

RVM allows you to manage different versions of Ruby and Gems. You can install the ruby ​​version using, for example

 rvm install 1.9.2 

Then you can use it using:

 rvm use 1.9.2 

Use specific gems for each project with a gemset.

If you want to continue posting names, you can configure gemsets; catalogs that will contain specific gems for a particular project.

 rvm gemset create myproject 

then you can use them like this:

 rvm use 1.9.2@myproject 

Automation

To automate the process of switching gems, pop .ruby-version and .ruby-gemset files to the project root directory. Download the Ruby version and the gemset name that you want to use inside them, and RVM select the correct gemset when you enter the project directory.

Install gems in your gemset

Install your gems in your gemset in the usual way using bundler if you use it:

 bundle install 

or just using the plain old:

 gem install mygem 

Gems will go in the right gemset.

Alternatives to RVM

You can also check rbenv, which does a similar job.

+10
Mar 20 '12 at 12:25
source share

You can use rvm

Then you can also use the Bundler , which perfectly manages gem dependencies.

In Gemfile

 gem "rails", "2.3.10" 

and in your application

 require 'rubygems' require 'bundler/setup' 

and you're done.

+6
Dec 07 2018-10-12T00:
source share

EDIT: Just saw your mention of RVM in a post. Definitely the way to go.

You will want to install RVM - this is an amazing package that will allow you to manage different Rubys and different sets of gems on one machine. You can easily and quickly switch back and forth.

Here's the installation guide: http://rvm.beginrescueend.com/rvm/install/

Once you get up, you can see all installed rubies on the command line using rvm list and switch using rvm use ruby-head , for example. RVM stores gems on each ruby ​​separately, which should help with your question.

+3
Dec 07 2018-10-12T00:
source share



All Articles