简体   繁体   中英

How to link already downloaded Rails gem to new version of Ruby?

I'm not clearly understanding the role of; RVM, RubyGems, Gemsets, Homebrew & Bundler, how they interact together and how I should use them to manage my envrionment, different applications, different Ruby versions, different Rails versions and everything's respective dependencies.

I've been happily coding using Ruby 2.3 and rails 5.0.3 for latest apps and older versions for some others, but through luck more than planning have not had any environment issues to date. I am just about to start the Agile Web Development with Rails 5 and I'm trying to get environment set up to match the tutorial. This leads me to needing to better understand RVM & Gemsets, RubyGems, Bundler, Homebrew so that I can now manage different Ruby and Rails versions on my machine.

First step has been to update my Ruby version which was 2.3.0 via rvm install ruby-2.4.2 , installed successfully.

This leads me to realise that despite having various Rails versions on my machine, 'linked' to older versions of Ruby, I don't have any Rails versions 'linked' to my new Ruby v2.4.2.

Question no.1) Surely I don't have to actually download another copy of my desired Rails version for this new Ruby v2.4.2? Can I not somehow 'link' the previously installed Rails version to this new Ruby v2.4.2?

Here's what rvm gemset list_all gives;

gemsets for ruby-2.2.2 (found in /Users/jamesbkemp/.rvm/gems/ruby-2.2.2)
=> (default)
   global

gemsets for ruby-2.3.0 (found in /Users/jamesbkemp/.rvm/gems/ruby-2.3.0)
=> (default)
   global

gemsets for ruby-2.4.2 (found in /Users/jamesbkemp/.rvm/gems/ruby-2.4.2)
=> (default)
   global

Question no.2) Does RVM's 'gemsets' do the same thing as Bundler? ie do I use only one or the other? In my case I've been using Bundler, so would rather stick with that if it's a case of either or.

Question no.3) So that I can better understand these environment management tools can anyone give me a high level overview of what I should be using RVM & Gemsets, HomeBrew & Bundler for, specifically which should be used to update what and where do the boundaries lie between each tool.

Thank you.

My workflow working with rvm is as follow
1 - I install a ruby version with $ rvm install 2.3.1
2 - Select the ruby version $ rvm use 2.3.1
3 - Now I create a gemset for encapsulate gem versions in a gemset avoiding versions conflicts with other apps, so $ rvm gemset create my_app
4 - Now I select the gemset $ rvm use 2.3.1@my_app
5 - Install a Rails version $ gem install rails -v 5.0.3
6 - Create the app, $ rails new my_app
Now you have your rails and gems installed on my_app gemset.
7 - Finally, I explicit in the app the ruby version and gemset used adding, in the my_app root path, a .ruby-version file containing 2.3.1 and a .ruby-gemset file containing my_app , so when I enter to my_app root path, rvm knows that it must change automatically to 2.3.1@my_app gemset and you don´t need to type $ rvm use 2.3.1@my_app each time.

Answering to your first question, maybe you have rails installed but only in one ruby global gemset -a global default gemset-, so if you install a new ruby version you must install again the rails gem in it. I recommend to create a gemset for each app because reduce gems collision troubles if you have different apps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM