RVM

How to Get Started and Manage Your Ruby Installations

It’s the night time before an enormous deadline, and simply before you press the button to deploy, you discover a small but essential bug! You open a terminal, sort within the command to run the code—and all you see is a page of errors. It’s these palm-sweating moments that make us ponder whether we made the right career choice. Configuring our methods and preserving them working is a wrestle most of us cope with repeatedly. Ruby Model Manager (RVM) attempts to remedy this drawback.

Ruby Version Supervisor (RVM) creates an remoted set up of Ruby in your $HOME directory. This idea makes it straightforward to run a number of versions of Ruby at the similar time, and eradicating it’s as straightforward as deleting one folder. In the looming deadline state of affairs, it’s straightforward to examine which version you’re utilizing, take away it, and reinstall it with the information that it’s isolated from the rest of the system.

This submit covers in detail how to install RVM from scratch, along with the newest model of Ruby for a single consumer on Linux, macOS, and Windows Subsystem for Linux. We additionally go in depth on how to install and handle totally different variations of Ruby. These directions are designed for a single consumer wanting an remoted installation in their $HOME listing. That is appropriate for particular person customers, however not for system administrators requiring multiple customers to access one set up or wanting to use RVM to deploy production software.

Getting ready your working system for set up

Before installing RVM, there are three libraries you want to set up:

  • GPG: an encryption program for verifying the supply of the appliance
  • curl: a program to download the script that installs RVM
  • Bash: a program to run the obtain script

Most operating techniques will come with these packages pre-installed, so examine first earlier than downloading.

Using the command terminal

Throughout this guide, I’ll be referencing the terminal. For many operating techniques, that’s the identify of the appliance that allows you to enter instructions which might be interpreted by the system. acOS has a terminal emulator, Linux has a console, and Windows also has a console.

Verifying the installation supply

RVM cryptographically indicators each launch, which requires validation on download. Configure the corresponding keys RVM requires to verify the signature by operating the following within the terminal:

gpg –keyserver hkp://pool.sks-keyservers.internet –recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

When run, this command will add the given keys to your local key store and enable verification of the RVM installation and show the next output:

gpg: directory ‘/Users/peter.grainger/.gnupg’ created
gpg: keybox ‘/Users/peter.grainger/.gnupg/pubring.kbx’ created
gpg: key 105BD0E739499BDB: 5 signatures not checked due to lacking keys
gpg: /Customers/peter.grainger/.gnupg/trustdb.gpg: trustdb created
gpg: key 105BD0E739499BDB: public key “Piotr Kuczynski ” imported
gpg: key 3804BB82D39DC0E3: 105 signatures not checked due to lacking keys
gpg: key 3804BB82D39DC0E3: public key “Michal Papis (RVM signing) ” imported
gpg: no finally trusted keys discovered
gpg: Complete number processed: 2
gpg: imported: 2

The above output exhibits that two public keys have been added to an area retailer. When RVM is put in, the discharge will probably be checked towards these keys to confirm the file came from the right source.

Installing RVM

Installation has barely totally different steps for Ubuntu in contrast to different operating techniques. Home windows is just supported if utilizing the Windows Subsystem for Linux and makes use of the identical instructions as for macOS and Linux (excluding Ubuntu).

Installing on Ubuntu

Ubuntu has a dedicated package deal obtainable to set up via the apt-get package deal supervisor.


Stackify Loves Developers


Install the required libraries to use Personal Package deal Archives

To permit the addition of the Private Package deal Archives (PPA), install the Ubuntu package deal software-properties-common.

Open a terminal, and run the following:

sudo apt-get update
sudo apt-get install -y software-properties-common

The above will replace the apt-get package deal supervisor with the newest references, then set up the software-properties-common library, which permits the addition of the RVM PPA.

To confirm if the previous command was profitable, run the following command:

dpkg-query -Wf’$Standing’ software-properties-common

This command queries the package deal supervisor to verify the given package deal was installed appropriately. If the above command was profitable, the terminal will show:

install okay put in

Add the Personal Package deal Archive for RVM

Add the PPA particularly for RVM using the following command. This can add the repository containing the RVM binary and permit installation.

sudo apt-add-repository -y ppa:rael-gc/rvm

This command will add the ppa:rael-gc/rvm repository to the interior listing Ubuntu holds to allow installation of RVM.

Install RVM

Update the installer and install RVM by getting into the next into the terminal:

sudo apt-get install -y rvm

This command installs the RVM software and provides the appliance the right permissions. The -y skips a affirmation prompt on install.

All other operating methods (macOS / subsystem for Linux / Linux)

All different working techniques are configured by following one step that downloads a script utilizing curl, which it then executes utilizing Bash. Don’t use root when operating this script; it’ll install RVM as the basis consumer, and it gained’t work appropriately for another consumer. Enter the next into the terminal:

curl -sSL https://get.rvm.io | bash

The above command first downloads a shell script, then pipes that shell script to Bash. The script is executed, and the appliance together with any configuration is downloaded and configured in your machine. No extra enter is required for the set up.

Using RVM

Verifying the installation is profitable

To start out using RVM for the primary time, run the next within the terminal. This solely wants to be run once after set up.

supply /and so on/profile.d/rvm.sh

This command will execute the rvm.sh script and permit you to run RVM within the current terminal.

To ensure RVM is working appropriately, instruct RVM to return the at present installed model by getting into the next into the terminal:

rvm –version

This command will present the present model of RVM installed on the working system. If the installation was profitable, the output ought to be comparable to the following, but might show a special model:

rvm 1.29.8 (guide) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

Installing Ruby utilizing RVM

Select a Ruby version

For those who’re already operating your software in manufacturing, then use the model of Ruby that surroundings is operating. Operating a unique model of Ruby regionally than what’s run in production might cause you unintended penalties. APIs are deprecated between versions of Ruby, and some methods behave in a different way or unexpectedly. In Ruby 1.8, the system technique proc returns a lambda; in Ruby 1.9, this is fastened to return a proc. Although they have comparable performance, there are some vital differences. Edge case points like this are very frustrating and value useful time finding the answer.

When you aren’t positive which model you’re utilizing, a device like Retrace might help work that out. You possibly can also learn how the server is configured and how the appliance is deployed to work out which model you must use.

In the event you aren’t restricted to a selected version of Ruby, it’s greatest to choose the newest secure one. The simplest means to get this info is to visit the official Ruby website. See the screenshot under, taken from the website, stating the present secure version is 2.6.3. This website also incorporates an inventory of the version numbers of all Ruby releases.

Set up Ruby

To install a version of Ruby using RVM, use the command rvm set up . So to set up version 2.6.3 of Ruby enter the following into the terminal:

rvm set up 2.6.3

Relying on your working system, the above command might use precompiled binaries or compile the Ruby binaries from source. If compiling from source, this may increasingly take a long time to complete.

To verify this set up labored appropriately, run the next in the terminal:

rvm record

This command will record all the put in versions of Ruby managed by RVM. The output of this command shall be comparable to the output under:

=* ruby-2.6.3 [ x86_64 ]# => – present
# =* – present && default
# * – default

This output exhibits every version of Ruby that RVM manages. Only one model of Ruby has been installed, and that model is the default and current model. When you close the terminal or restart your machine, the current model of Ruby can be 2.6.three.

To confirm the current model of Ruby, run the following:

ruby -v

It will present the present model of Ruby operating in the terminal. The output ought to be comparable to this:

ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]

Using Gems

Putting in a gem utilizing RVM is identical as when installing by way of a system set up of Ruby. The next command will set up the pry gem:

gem set up pry

If installation of the pry gem is profitable, the final line of the output will probably be what follows:

Completed installing documentation for method_source, coderay, pry after 3 seconds

3 gems installed

This output exhibits that pry was installed together with two dependencies, coderay and method_source. These dependencies are required for pry to perform.

To test the gem was successfully installed, run the following within the terminal:

pry

The above command will start the pry REPL and verify the installation of the gem was profitable.

Putting in an older model of Ruby

Should you’re working on multiple venture and every undertaking uses a special version of Ruby, you might need multiple version of Ruby installed. To put in an previous model of Ruby utilizing RVM, enter this into the terminal:

rvm set up 2.5

This command will set up version 2.5 of Ruby, but won’t set it as the present model getting used. The default current model of Ruby will remain as 2.6.3.

To see the current model of Ruby, enter the following into the terminal:

rvm record

This command will now output two variations of Ruby, 2.5.5 and 2.6.3, but could have 2.6.3 as the present and default version proven in the following output:

ruby-2.5.5 [ x86_64 ]=* ruby-2.6.3 [ x86_64 ]# => – present
# =* – present && default
# * – default

Altering between Ruby variations for the present session

To vary the model of Ruby you’re using briefly, for as long as you have got your terminal open, use the following command:

rmv use 2.5.5

The above command will set the present working model of Ruby to 2.5.5. Operating the command rvm listing within the terminal will output the under:

=> ruby-2.5.5 [ x86_64 ]* ruby-2.6.three [ x86_64 ]# => – present
# =* – current && default
# * – default

The output exhibits that ruby-2.5.5 is the current version, indicated by the image =>, and ruby-2.6.3 is the default model, indicated by the image *.

This can be verified by typing ruby -v in the terminal, which can output this:

ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-darwin18]

This output exhibits that the present version of Ruby is 2.5.5.

Open a new terminal and enter the command ruby -v. This can output the following:

ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]

This output exhibits that version 2.6.3 is the default model RVM and might be used when beginning a new terminal session.


Stackify Loves Developers


Setting a default model of Ruby across periods

To set version 2.6.three because the default Ruby model across all periods, enter the following in the terminal:

rvm use 2.6.three –default

This command will set the default model of ruby to 2.6.3.

To verify this works throughout all periods, open a new terminal and sort ruby -v. The output shall be as follows:

ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]

Uninstalling a Ruby model

To uninstall any version of Ruby you previously installed utilizing RVM, use this command:

rvm uninstall 2.6.3

This command will uninstall version 2.6.3 of Ruby. Operating rvm record once more will outcome within the output under:

ruby-2.5.5 [ x86_64 ]# Default ruby not set. Attempt ‘rvm alias create default ‘.
# => – present
# =* – present && default
# * – default

The output exhibits that now only version 2.5.5 of Ruby is installed.Model 2.6.three has been uninstalled and not appears within the record.

Mechanically changing your Ruby version for every software

But what if in case you have a number of purposes with totally different variations of Ruby for every? How do you retain monitor of which model to use and keep in mind to change to the right version? RVM has the solution within the type of a file named .ruby_version. This file tells RVM to routinely change the present Ruby version to the one outlined in the file.

To make a .ruby-version file, open your terminal within the root of your Ruby software directory and enter the following:

echo ‘2.6.2’ > .ruby-version

The above command will create a file referred to as .ruby-version with the contents 2.6.2. Each time you navigate to that software folder, the model of Ruby will mechanically change to 2.6.2.

If that version isn’t put in, then the output from the terminal might be as follows:

Required ruby-2.6.2 is just not installed.

To install do: ‘rvm set up “ruby-2.6.2″‘

Making RVM your Rubies manager

Now that you’ve RVM put in and are in a position to change between totally different variations, it should take away a few of the headache when configuring your system. Nevertheless, this is simply the tip of the iceberg. RVM is a strong device that can be used regionally and also deployed to your production server. I might encourage you to head over to the official RVM web site with information about the highly effective integrations with Capistrano, Heroku, Jenkins, and many extra. For the complete listing of integrations, see the integrations page on rvm.io.

I can’t promise RVM will make your software releases much less nerve-racking, but it’s going to make establishing your machine rather a lot easier.

Start Free Trial

About Peter Grainger

This publish was written by Peter Grainger. Peter is a senior engineer at Sage with over 10 years of experience in numerous industries similar to satellite tv for pc communications, public sector, and finance. He’s content to automate himself out of most jobs and is happiest deleting code relatively than writing more. Peter has deep information of Java, JavaScript, Node, MongoDB, and GitLab.

  • RVM: How to Get Started and Manage Your Ruby Installations – June 1, 2019
  • Ruby Debugger Using Visible Studio Code – Might 2, 2019