Gem, Bundle, Bundler and RVM in Ruby

Tram Ho

How are gem, bundle, bundler and RVM different? One of the first challenges that developers are familiar with Rails is to distinguish these terms. Most Rails developers ignore Ruby and therefore often get confused between the above terms. If you are one of those cases, keep reading. In this article we will clarify these concepts together.

1. What is GEM

Gem is a Ruby library. It is no different from libraries of other normal languages ​​like PHP, Java or Python but the library in Ruby is called GEM. Only that simple.

Note: Rails is also a Ruby GEM !!!

After understanding what Gem is, the next question is that is how to install Gem? The answer is to use a program called RubyGems preinstalled with Ruby version 1.9 and above. This program can be run on the command line with the name gem. For example, to install a Gem named drip, run the following command:

2.Bundle What is

Bundler is a tool to manage the installation, updating, removal, configuration and management of version of GEM.

For example, to install Rails you can run the command:

Ok, but I just heard that I can use RubyGems on top of installing Gem and what about Bundle now?

The answer is that you should use Bundle to install Gem instead of RubyGems!

Why? Because Bundle doesn’t stop at updating and uninstalling, an important feature of Bundle is that version management of Gem will be installed.

For example, if in a project you need two library letters A and B.

Library A depends on C library version 1.0, when installing A, we will have to install C version 1.0 and above. Meanwhile library B also needs C but version 1.1. Now using Bundle we will not need to choose which version of C will be installed which will be done by this tool.

It’s that simple, but I have to use a library like that, so why not do it manually. If you are wondering, just imagine that you have a project that requires 100 libraries and each library only needs a dependent library and each dependent library has another dependent library …. You already understand why, right?

In addition to those who are curious, Bundle is essentially a Ruby GEM. Surprise? Ok if you are surprised, imagine the Bundle is like a Gem for managing other gems. Similarly, when using a computer, on the operating system we also have software to manage other software (also called software package manager).

Note: You should use Bundle to install Gem instead of RubyGems !!!

3. What is Bundler What?

Bundler = Bundle. Only that simple.

Why does it have two names? This is fine:))

4. What is RVM?

RVM stands for Ruby Version Manager as a software that manages different versions of Ruby on the system so that we can easily change between the Ruby versions used.

For example, now your company has two projects, one project with Ruby 1.9, a project made with Ruby 2.4. If you do not use RVM, imagine how hard it is for us to try each time we want to switch to the Ruby version we need to use.

Using RVM switching between versions of Ruby is done simply through a command:

Conclude

Ruby is a popular programming language besides other scripting languages ​​such as PHP, Python … You may be confused with the terms that appear when you first learn this language but if you overcome these barriers will surely love this programming language!

References:

  1. https://github.com/rails/rails
  2. https://www.codehub.vn/Gioi-thieu-ve-RVM-trong-Ruby
Share the news now

Source : Viblo