Install Ruby: A Step-By-Step Guide

David Morales David Morales
/
Miners extracting vivid red rubies from rocky walls in a dimly lit underground mine, surrounded by tools and wooden beams.

Ruby is widely used for web development thanks to the Ruby on Rails framework. This guide covers my recommended method to install Ruby on different operating systems, and how to maintain different versions effectively.

Installing Ruby on macOS and Linux

It is common to work with different projects on your machine, and each one may require a different version of Ruby. For this it is useful to have a version manager tool that allows you to switch between them automatically and without conflicts.

The version manager tool recommended by DHH (creator of Ruby on Rails) is Mise, as you can see in this post in X. It is also used in the installation guides on the official Ruby on Rails website.

Installing Mise

Depending on your operating system and the package manager you use, the installation of Mise may vary. I recommend you to check the official guide and follow the instructions for your operating system.

The YJIT compiler

Broadly speaking, there are two types of languages: compiled and interpreted. Ruby is an interpreted language, meaning the code of your application is interpreted at runtime. This approach is highly flexible but also slower than a compiled language, which translates the application’s code beforehand into machine code optimized for the CPU on which it’ll run.

To increase Ruby’s speed, there’s currently the YJIT compiler, which performs a similar function to compiled languages, but on-the-fly (at runtime). In other words, it combines the best of both worlds: the flexibility of interpreted languages with the speed of compiled ones.

However, the YJIT compiler isn’t enabled by default, as it’s programmed in Rust and thus requires the Rust compiler to be installed before installing Ruby. Therefore, your first step should be installing Rust.

Installing Rust

Mise uses the recommended method to install Rust, which is through the rustup tool. You can install it by running the following command:

Terminal window
mise use -g rust

Preparing the build environment

Mise uses ruby-build under the hood to install Ruby. Therefore, you need to have the necessary dependencies installed to compile Ruby from source. I recommend you to take a look at this wiki and follow the instructions for your operating system.

Installing a Ruby version

The first thing to consider is which version of Ruby you want to install.

If your project has a .ruby-version file, open it and there you will find the version you need.

If for example you wanted to install version 3.4.2, you would do it this way:

Terminal window
mise use -g [email protected]

If you want to install the latest instead, just run this:

Terminal window
mise use -g ruby

If you want to see a list of the versions you have installed, you can do it with this command:

Terminal window
mise ls ruby

The Ruby installation includes the gem command to manage your libraries. It is a package manager that communicates with the RubyGems repository.

Don’t forget to install bundler globally to manage the dependencies of your projects:

Terminal window
gem install bundler

Checking the YJIT version

To check if the YJIT compiler is enabled, you can run the following command:

Terminal window
ruby --yjit -v

The output should be something like this:

Terminal window
ruby 3.4.2 (2025-02-15 revision d2930f8e7a) +YJIT +PRISM [arm64-darwin24]

Pay attention to the +YJIT part, which indicates that the YJIT compiler is enabled.

Running Ruby

Now you can place yourself in some directory and check which version would respond:

Terminal window
mise current ruby

You can also run ruby -v to see more data, such as build information or the architecture.

Installing Ruby on Windows

Although Ruby has native support on Windows, I recommend you to enable WSL (Windows Subsystem for Linux), so you can use the embedded Linux alongside your Windows apps.

It is as easy as opening a terminal in administrator mode and running the following:

Terminal window
wsl --install

Reboot to finish the installation. Windows will install Ubuntu by default, but if you prefer another system you can have a look at the official guide by Microsoft.

Now that you have WSL ready, you can follow the instructions above to install Mise, and finally install Ruby.

Updating your Ruby tools

Updating Mise

When a new version of Ruby is released, you have to update Mise’s Ruby integration first to support its installation:

Terminal window
mise upgrade

This will also notify you if there are new versions of the other tools installed with Mise, such as the Rust compiler.

Updating Ruby

With Mise’s Ruby integration already updated, you can now start the installation of the new version:

Terminal window
mise use -g ruby@VERSION

Where VERSION is the new version you want to install.

Note that when you install gems, they are saved in the directory of the corresponding Ruby version, so you will have to reinstall them for the new Ruby version you just installed.

First reinstall bundler globally:

Terminal window
gem install bundler

Then, for each project, update the .ruby-version file with the version you just installed. Then run the following command:

Terminal window
bundle install

This will reinstall the gems and you will have the project updated to the new Ruby version.

Don’t forget to remove the previous Ruby version. You can do it with this command:

Terminal window
mise uninstall ruby@VERSION

Where VERSION is the previous version.

Updating RubyGems

I recommend updating the gems manager with the latest changes from the RubyGems repository:

Terminal window
gem update --system

Test your knowledge

  1. After installing a new version of Ruby, why is it necessary to reinstall your gems for that version?

  1. Why you should use a separate tool (like Mise) to install Ruby rather than relying on a package manager?

  1. What is the primary reason for uninstalling old Ruby versions when you upgrade?