Ruby Version Manager (RVM)

 

Overview

This article walks you through installing RVM as well as a custom version of Ruby and/or Rails.

Background

Ruby Version Manager (RVM) is a utility that allows you to add, remove, and install multiple versions of Ruby and its libraries under your website user.

Prerequisites

This article assumes you have created a shell user and are able to log into your server via SSH.

VPS and Dedicated servers only

Due to the amount of memory Ruby on Rails uses, running a Ruby app is only available on a VPS or Dedicated server.

Installing RVM

This section installs RVM under your shell user and configures it to load automatically.

  1. Log in to your server via SSH.
  2. Make sure you're in your user's home directory:
    [server]$ cd ~
  3. Install RVM's public keys. This creates a new folder under your user named /.gnupg with the public key.
    [server]$ gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
  4. Install the latest stable version of RVM:
    [server]$ curl -sSL https://get.rvm.io | bash -s

    This command does the following:

    • Creates a new folder under your user named /.rvm
    • Adds this line to your .bash_profile
    [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
    • Adds this line to your .bashrc file:
    # Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
    export PATH="$PATH:$HOME/.rvm/bin"
  5. Unset your GEM_HOME:
    [server]$ unset GEM_HOME
  6. Update your new RVM install:
    [server]$ . ~/.rvm/scripts/rvm
  7. Disable autolibs.

    If autolibs is not disabled, the Ruby (and Rails) installation fails due to permission issues.

    [server]$ rvm autolibs disable
  8. Check if RVM is installed and functioning:
    [server]$ rvm --version

Installing a custom version of Ruby

Once RVM is configured, you can install any version of Ruby you like.

  1. Obtain a list of available versions to install:
    [server]$ rvm list known

    Several interpreters are listed, such as MRI, JRuby, Rubinius, etc. You should install a version under the MRI section. For example:

    # MRI Rubies
    [ruby-]3.0[.7]
    [ruby-]3.1[.5]
    [ruby-]3.2[.6]
    [ruby-]3[.3.6]
  2. Install the exact version of Ruby you require. This example installs version 3.3.6:
    [server]$ rvm install 3.3.6
  3. Set this version as default.
    [server]$ rvm use 3.3.6 --default
  4. Check the version of Ruby to confirm it's been updated.
    [server]$ ruby -v

Installing a custom version of Rails

Install the latest version of Rails using this command:

[server]$ gem install rails

You could also run the following to install a specific version:

[server]$ gem install rails --version 8.0.0

Troubleshooting

If your Ruby application won't start because of a missing gem, then you must install it locally using Bundler. See this article for more information about using Bundler.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?