0
0
RubyHow-ToBeginner · 3 min read

How to Install Ruby Using RVM: Step-by-Step Guide

To install Ruby using rvm, first install rvm by running its installation script, then use rvm install ruby to install the latest Ruby version. Finally, set the installed Ruby as default with rvm use ruby --default.
📐

Syntax

Here are the main commands to install Ruby using rvm:

  • curl -sSL https://get.rvm.io | bash -s stable: Installs the stable version of RVM.
  • rvm install ruby: Installs the latest stable Ruby version.
  • rvm use ruby --default: Sets the installed Ruby as the default version.
bash
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install ruby
rvm use ruby --default
💻

Example

This example shows how to install RVM, then install Ruby version 3.2.2, and set it as default.

bash
curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm install 3.2.2
rvm use 3.2.2 --default
ruby -v
Output
ruby 3.2.2p123 (2024-03-15 revision 12345) [x86_64-linux]
⚠️

Common Pitfalls

Common mistakes include:

  • Not loading RVM environment after installation with source ~/.rvm/scripts/rvm.
  • Trying to install Ruby without required dependencies (like build tools).
  • Not setting the default Ruby version, causing system Ruby to be used.

Always check RVM installation instructions for your OS to install dependencies first.

bash
## Wrong: skipping source command
rvm install 3.2.2
ruby -v  # May show system Ruby, not RVM Ruby

## Right: load RVM environment
source ~/.rvm/scripts/rvm
rvm install 3.2.2
rvm use 3.2.2 --default
ruby -v  # Shows correct Ruby version
📊

Quick Reference

CommandDescription
curl -sSL https://get.rvm.io | bash -s stableInstall RVM stable version
source ~/.rvm/scripts/rvmLoad RVM environment into shell
rvm install rubyInstall latest Ruby version
rvm install 3.2.2Install specific Ruby version 3.2.2
rvm use ruby --defaultSet installed Ruby as default
ruby -vCheck current Ruby version

Key Takeaways

Install RVM first using the official installation script.
Always load RVM environment with source command before using it.
Use rvm install to get the Ruby version you want.
Set your Ruby version as default to avoid conflicts with system Ruby.
Check Ruby version with ruby -v to confirm installation.