RVM and Gemset
GemSet- A gemset is just a container you can use to keep gems separate from each other. Creating a gemset per project allows you to change gems (and gem versions) for one project without breaking all your other projects. Each project need only worry about its own gems.
RVM-
RVM is a command-line tool for managing multiple ruby versions and also uses a separate gemset for each rails app.
RVM is a command-line tool that allows you to easily install, manage, and work with multiple ruby environments from interpreters to sets of gems.
[ source: https://rvm.io/ (official rvm website) ]
Ruby Version Manager, often abbreviated as RVM, is a software platform for Unix-like operating systems designed to manage multiple installations of Ruby on the same device. The entire ruby environment including the Ruby interpreter installed RubyGems, and documentation is partitioned.
[ source: Wikipedia ]
Why we need RVM
Let’s see an example.
Suppose, you have installed Ruby version 2.4.1 and created a rails project with Rails version 5.1
Fews days later you want to run another rails app with Ruby version ruby-2.6.1
Now you will uninstall Ruby version 2.4.1 and install Ruby version ruby-2.6.1, right?
If the answer is: I am not sure what to do!
Then RVM is the right solution for UNIX-like operating systems.
Because RVM can manage multiple ruby and rails versions easily.
How RVM works:
The concept is very simple.
RVM installs different ruby versions and gemset in different directories.
And when a programmer selects a gemset from a command line, RVM creates a symbolic link for ruby to that specific ruby version and gemset.
Example:
I have installed RVM, ruby-2.4.1, and ruby-2.6.3
When I normally run the command “$ which ruby” in the terminal I see this path:
/home/user/.rvm/rubies/ruby-2.4.1/bin/ruby
I’ll run “$ rvm use 2.6.3”. Now I run “$ which ruby”, and I see a different path:
/home/user/.rvm/rubies/ruby-2.6.3/bin/ruby
You can also create different gemset for different Rails App under ruby version, you will not face gem version conflicts between multiple Rails projects.
How to install and use RVM in Ubuntu:
You can follow instructions from official RVM website: https://rvm.io/
Install RVM stable version:
$ \curl -sSL https://get.rvm.io | bash -s stable
Install a ruby version:
$ rvm install 2.4.1
Suppose you have a rails app rtl_shop, Create a gemset for this Rails App:
$ rvm use — create 2.4.1@rtl_shop
When you work in rtl_shop, select this gemset:
$ rvm use 2.4.1@rtl_shop
Now, If you run “$ bundle install”, gems will be installed in this selected gemset.
RVM supports .ruby-version and .ruby-gemset:
You can create a .ruby-version and a .ruby-gemset file in the Rails App root directory.
in .ruby-version file, write the ruby version:
2.4.1
in .ruby-gemset file, write the gemset name:
rtl_shop
When you cd to that directory, RVM will switch to that ruby version (from .ruby-version file) and gemset (.ruby-gemset file).
If the ruby version is installed and the gemset is not created, RVM will create that gemset.
RVM Alternatives:
RVM alternatives are available. rbenv is another popular alternative of RVM.
Here you will find other RVM alternatives: https://ruby.libhunt.com/rvm-alternatives
I found that RVM always works fine in development, staging, and production environments.
Comments
Post a Comment