How to make a specific default gem version?

I have two versions of a ruby ​​gem.

json (default: 2.0.2, 1.8.6) 

Here, the latest version is installed by default; however i need json 1.8.6 install by default. Is there any way to make old versions of gemstones by default? Because I can not remove the standard version of json. Need a transition between available versions of gem.

+5
source share
4 answers

A Gemfile is required, but not enough. You must also change the line

 require 'json' 

to

 require 'bundler/setup' Bundler.require :default 

This will require all the gems specified in your Gemfile , without group .

+3
source

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 the terminal.

+2
source

Add This Your Gemfile

 gem 'json', '1.8.6' 

Now run this on the command line

 bundle update 

This should install the required version.

+1
source

Since you use RVM to manage your versions of Ruby, as you said in the comments, there is a simple solution: create a private package for this application and install only the version of the gem that you need in this kit.

Here's how you can do it:

1) Enter the directory of your application;

2) Enter the following command

 rvm use ruby-2.4.0@your _app_name --ruby-version --create 

(I assume you are using Ruby 2.4.0. If this is not your version, replace it accordingly in the command above.)

3) Install the supplier gem

 gem install bundler 

4) Make sure your Gemfile announces the version of the gem you need. In this case, it should have the line:

 gem "json", "1.8.6" 

5) Now run

 bundle install 

And you're done!

WARNING: This procedure ensures that json gem is version 1.8.6. But you may have problems with your bundle install if installing a different gem requires a newer version of json gem . In this case, you will have to resolve this conflict differently.

To learn more about the different packages for different applications, read this .

Hope this helps.

+1
source

Source: https://habr.com/ru/post/1264922/


All Articles