Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a specific gem version as default?

I have two versions of ruby gem.

json (default: 2.0.2, 1.8.6) 

Here, the latest version is set to default; however I need json 1.8.6 to be set as default. Is there anyway to make the older versions of the gem as default? cos I am unable to uninstall the default json version. Need a switch between available gem versions.

like image 229
Prashanth Sams Avatar asked Mar 02 '17 06:03

Prashanth Sams


People also ask

How do I specify a gem version?

There are several ways to specify gem versions: Use a specific version: gem "name-of-gem", "1.0" . You can find specific versions on Rubygems.org (provided that's the source you”re using) by searching for your gem and looking at the “Versions” listed. Use a version operator: gem "name-of-gem", ">1.0" .

How do you make a default gem?

gem env – try to search in provided list under GEM PATHS, in specifications/default. remove there bundler-VERSION. gemspec. install bundler, if you don't have specific: gem install bundler:VERSION --default.


2 Answers

Check what you have with:

gem list json 

Set the one you want:

gem install --default -v1.8.6 json 

This is most useful for things like "bundler"!!! For other things, using bundler and a Gemfile is probably a better choice.

like image 177
mcr Avatar answered Oct 11 '22 12:10

mcr


Add

gem 'json', '1.8.6' 

to your Gemfile or execute

gem install 'json' -v 1.8.6 # may require sudo if you use system ruby 

from terminal.

like image 22
marmeladze Avatar answered Oct 11 '22 11:10

marmeladze