How to Use Multiple Ruby and Rails Versions with RVM

As a Ruby or Ruby on Rails developer, you often find yourself juggling projects that rely on different versions of Ruby or Rails. Luckily, RVM (Ruby Version Manager) makes this task painless. In this post, I’ll walk you through setting up and managing multiple Ruby and Rails versions using RVM.

🧰 What is RVM?

RVM is a command-line tool that allows you to easily install, manage, and switch between multiple Ruby environments. This is especially useful when working on legacy apps or testing across versions.

Installing RVM (If Not Already Installed)

First, install RVM with the latest stable Ruby:

\curl -sSL https://get.rvm.io | bash -s stable --ruby

Reload your shell

source ~/.rvm/scripts/rvm

Verify installation:

rvm -v

Installing Multiple Ruby Versions

You can install any Ruby version using the rvm install command:

rvm install 3.4.2

List all installed Ruby versions:

rvm list

Switch to a specific version:

rvm use 3.4.2

Set a default Ruby version:

rvm use 3.4.2 --default

Creating and Using Gemsets

Each Ruby version can have isolated gemsets (great for separating project dependencies):

Create a gemset:

rvm use 3.4.2
rvm gemset create version_8

Use the gemset:

rvm use 3.4.2@version_8

Create and use in one line:

rvm use 3.4.2@version_8 --create

List gemsets:

rvm gemset list

Installing Rails in a Specific Ruby + Gemset

After switching to the desired Ruby + gemset:

gem install rails -v 8.0.2

Verify Rails:

rails -v

You can now create or run projects using that specific Rails version.

Making It Project-Specific with .ruby-version and .ruby-gemset

To ensure your project always uses the correct Ruby and gemset:

Create these two files in your project root:

echo "3.4.2" > .ruby-version
echo "version_8" > .ruby-gemset

Now, every time you cd into the project directory, RVM will automatically switch to the correct environment.

Switching Between Projects

Just cd into your project folder. RVM reads the .ruby-version and .ruby-gemset files and loads the environment automatically. It’s that easy.

Cleaning Up

Uninstall Ruby versions:

rvm uninstall 3.4.2

Delete gemsets:

rvm gemset delete version_8

Conclusion

Using different Ruby and Rails versions is easy with RVM. Just set it up once, and switch between projects without any mess.