5

Ruby Version Manager (RVM)

 3 years ago
source link: https://help.dreamhost.com/hc/en-us/articles/217185247-Ruby-Version-Manager-RVM-
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Ruby Version Manager (RVM)

Overview

If your Ruby application won't start because of a missing gem, then you must install it locally using Bundler. For more information about using Bundler, please visit the following page:

Ruby Version Manager (RVM) is a utility that allows you to add your own personal version of Ruby to a user. It allows you to add, remove, or have multiple versions of Ruby and its libraries live in your user directory.

This article walks you through how to manually install RVM as well as a custom version of Ruby and/or Rails. Once complete, you can then enable Passenger within your panel and select which version of Ruby you wish to use with your site.

Installing RVM

To get started, you'll first need to install RVM under your shell user and set it up to load automatically. Visit the Creating a user with Shell (SSH) access article to make sure your user is a Shell user. Then you can log in to your server via SSH to run the following commands in your user's directory.

  1. Make sure you're in your user's home directory:
    [server]$ cd ~
  2. Install RVM's public keys:
    [server]$ gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

    This creates a new folder under your user named /.gnupg with the public key.

  3. Install the latest stable version of RVM:
    [server]$ curl -sSL https://get.rvm.io | bash -s

    This command does the following three things:

    • 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"
  4. Run this to unset your GEM_HOME:
    [server]$ unset GEM_HOME
  5. Run this to source your new RVM install:
    [server]$ source ~/.rvm/scripts/rvm
  6. Run the following to disable autolibs:
    [server]$ rvm autolibs disable
  7. Now check if RVM is installed and functioning:
    [server]$ rvm --version
    rvm 1.29.12-next (master) by Michal Papis, Piotr Kuczynski, Wayne E. Seguin [https://rvm.io]

Installing any version of Ruby you wish

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

You must first disable autolibs. If autolibs is not disabled, the Ruby installation fails due to permission issues.

  1. Run the following to get a list of available versions to install:
    [server]$ rvm list known
    dh-kb-important-icon.svg

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

    # MRI Rubies
    [ruby-]1.8.6[-p420]
    [ruby-]1.8.7[-head] # security released on head
    [ruby-]1.9.1[-p431]
    [ruby-]1.9.2[-p330]
    [ruby-]1.9.3[-p551]
    [ruby-]2.0.0[-p648]
    [ruby-]2.1[.10]
    [ruby-]2.2[.10]
    [ruby-]2.3[.8]
    [ruby-]2.4[.10]
    [ruby-]2.5[.9]
    [ruby-]2.6[.7]
    [ruby-]2.7[.3]
    [ruby-]3[.0.1]
  2. Install the exact version of Ruby you require. This example installs version 3.0.1:
    [server]$ rvm install 3.0.1
  3. You can now tell your system to use this version by default:
    [server]$ rvm use 3.0.1 --default
  4. Check the version of Ruby to confirm it's been updated.
    [server]$ ruby -v
    ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]

Installing any version of Rails you wish

You must first disable autolibs. If autolibs is not disabled, the Rails installation fails due to permission issues.

  1. Run this command to install the latest version of Rails:
    [server]$ gem install rails
  2. Or you can install a specific version:
    [server]$ gem install rails --version 6.0.3.2
  3. View a full list of available versions at rubygems.org:

Enabling RVM using the DreamHost panel

You can now visit the How to Enable RVM article to specify the version of Ruby you installed above for any specific domain running Passenger.

dh-kb-important-icon.svg

Shared servers

DreamHost support is unable to assist with RVM installs on a Shared server. However, if you have installed RVM on Shared hosting, do not follow the 'How to enable RVM' article. Instead, add the following to an .htaccess file in your Ruby app:

PassengerRuby /home/username/.rvm/wrappers/ruby-2.7.1/ruby

Make sure to change username to your Shell user. and the version of Ruby to your app's version.

See also

Did this article answer your questions?


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK