The Ruby Version Manager

RVM (Ruby Version Manager) which works with the rvm command, helps developers to start building applications with the Ruby interpreter.

It simultaneously, supports several versions of Ruby and comes packed with built in tools to create virtual environments called gemsets. Using the RVM, it is possible to create different virtual environments, between different stages of deployment. Such that each one is built to meet custom dependencies and packages, based on the default Ruby installation. Able to work the same way anywhere.

RVM Gemsets

The advantage of RVM is in how it creates isolated run time environments, which are dedicated Ruby Containers for applications which would access only the resource in each of them.

Preparing the system

CentOS distributions come with very few applications and most of the known tools and applications needed to get a project up and running are not present. For our needed installation, we would require libraries and development tools, which do not ship by default with CentOs. These have to be downloaded ad installed before we begin. Using the YUM package manager, that ships with the CentOs software, a collection of commonly used tools and applications are ready to be downloaded. To get started with the necessary development tools, run the following:

 yum groupinstall -y development  
or
 yum groupinstall -y 'development tools'  

Note: The first version might not work on older distributions of CentOS.

Downloading And Installing RVM

After preparing our system with the tools needed for development and deployment of the ruby applications, such as a compiler for ruby. It is time to get the RVM downloaded and installed.

RVM was created to make the whole process of installing Ruby and managing its run time environments easy. The process of getting RVM downloaded and installed is also simplified.

In order to get started with download and installation for RVM, run the following:

 curl -L get.rvm.io | bash -s stable  

And to create a system environment using RVM shell script:

 source /etc/profile.d/rvm.sh  

Installing Ruby 2.1.0 On CentOS 6.5 Using RVM

The next step after the RVM download, and system environment configuration, to begin work on Ruby All that is needed from now on to work with Ruby 2.1.0 (or any other version), after downloading RVM and configuring a system environment is the actual installation of Ruby from source - which is to be handled by RVM.

In order to install Ruby 2.1.0 from source using RVM, run the following:

 rvm reload 
rvm install 2.1.0  

Setting Up a Ruby Version As The Default Interpreter

Working with multiple Ruby applications which are already in production, might require different versions of the Ruby interpreter for each one.

Although, under most circumstances, the most recent versions of the interpreter is what you would need for your applications. An excellent features of the RVM is its abiity to facilitate the set up of a default Ruby version for general use and to switch from it to other versions when necessary.

To check your interpreter version, run the following:

ruby --version 
# ruby command is linked to the selected version of Ruby Interpreter (i.e. 2.1.0)  

To see all the installed versions of Ruby, use the following command:

 rvm list rubies
To set a version of Ruby as the default, run the following:
 # Usage: rvm use [version] --default
rvm use 2.1.0 --default

Working With Different Ruby Installations

If you want to use another version for the current session, omit the --default flag:

# Usage: rvm use [version]
rvm use 2.1.0  

Working With RVM gemsets

An RVM gemset consist of a virtual environment located on a disk, within which all application related packages such as dependencies and libraries, are located and used by a single application. An example application is your website.

An RVM gemset consist of a virtual environment located on a disk, within which all application related packages such as dependencies and libraries, are located and used by a single application. An example application is your website.

Working With RVM gemsets

An RVM gemset consist of a virtual environment located on a disk, within which all application related packages such as dependencies and libraries, are located and used by a single application. An example application is your website.

For developers, who have not used multiple versions of programing environments, as made possible through gemsets, the process might appear unnecessary and cumbersome. Howeer, as you continue managing and developing your applications , the benefits begin to become visible. You find out that, the use of environments , for the development and production stages of your applications, make them simpler to maintain.

In order to create a new gemset container for a Ruby application, run the following commands:

# Usage: rvm gemset [create/use] [name] 
# Create a new gemset using the default Ruby interpreter (2.1.0) 
# Run: rvm use [version] if you wish to work with another 
# Example: rvm use 2.0.0 
rvm gemset create myapp

# Switch to using the new gemset called *myapp*
rvm gemset use    myapp

To simpler version of the above code is :

 # Usage: rvm use [version]@[name] --create 
rvm use 2.1.0@myapp --create 

From this point all subsequent actions (for this set up) such as Ruby gem installation, would only be for the newly environment. To install a gem in it:

 gem install [package]

This translates to having a package installed inside the gemset, such that no other application would be able to access it.

You can also empty the gemset if you need to start afresh, with the following command:

 # Usage: rvm gemset empty [name]
rvm gemset empty myapp

You can also delete a gemset by using the delete argument passed to rvm:

 # Usage: rvm gemset delete [name]
rvm gemset delete myapp

Phanerus Banner