rubyguides

Installing Ruby: macOS, Linux, and Windows

Ruby is a versatile programming language powering everything from web applications to automation scripts. Before you can start writing Ruby code, you need to get Ruby installed on your machine. This tutorial walks you through installing Ruby on macOS, Linux, and Windows using the most reliable methods.

Before you begin

Installing Ruby is the first practical step in learning the language, and the method you choose matters more than people expect. If you only need the system version for quick experiments, the defaults may be enough. If you plan to build projects, though, a version manager gives you more control and makes upgrades much easier later.

The simplest mental model is this: Ruby is the language, but the installation method is the tool you use to keep Ruby versions organized on your machine. Once that distinction is clear, it becomes easier to choose between Homebrew, rbenv, RVM, RubyInstaller, or WSL without feeling like every option is permanently right or wrong.

For a good next step after installation, see the Getting Started with Ruby tutorial and the Ruby Gems guide. Those pages show how to verify the setup and start using Ruby for real work.

TL;DR

Use a version manager if you want flexibility, use RubyInstaller on Windows, and use Homebrew or rbenv on macOS depending on whether you want simple setup or version control. The key is to end up with a Ruby version you can verify from the terminal and update later without breaking your environment.

Why Ruby?

Ruby was designed to make developers happy. Its elegant syntax reads like natural English, and its philosophy of “convention over configuration” has influenced countless frameworks—including Ruby on Rails, one of the most popular web frameworks in the world.

Whether you’re building web applications with Rails, scripting automation tasks, or learning programming for the first time, Ruby is an excellent choice.

If you are brand new to Ruby, do not worry about picking the perfect installation path on day one. Any method that gets a working ruby --version output is enough to start learning. You can always move to a version manager later once you have a better sense of how you want to use Ruby.

Installing Ruby on macOS

macOS comes with Ruby pre-installed, but it’s often an older version. For development, you’ll want a newer, manageable version.

Method 1: using Homebrew

Homebrew is the macOS package manager that makes installing development tools straightforward.

First, install Homebrew if you haven’t already. The curl command below downloads and runs the official installer, which handles the rest for you:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Then install Ruby. Homebrew places it in a versioned directory under /usr/local or /opt/homebrew, separate from the macOS system Ruby:

This keeps the Homebrew-managed interpreter separate from the older system Ruby used by macOS tools. You can update or remove it later without changing /usr/bin/ruby.

brew install ruby

Homebrew installs Ruby to /usr/local/bin or /opt/homebrew/bin, which takes precedence over the system Ruby. Without the PATH adjustment, your terminal may still find the older system Ruby first. To use Homebrew’s Ruby by default, add this to your shell configuration file (~/.zshrc for Zsh or ~/.bash_profile for Bash):

export PATH="/usr/local/opt/ruby/bin:$PATH"
# For Apple Silicon Macs:
# export PATH="/opt/homebrew/opt/ruby/bin:$PATH"

After updating the shell configuration, restart your terminal or source the file to apply the change immediately. Running which ruby afterward should now return the Homebrew-installed path rather than /usr/bin/ruby:

source ~/.zshrc

Method 2: using rbenv

rbenv is a lightweight version manager that lets you switch between Ruby versions easily. It’s perfect when you need to test your code against different Ruby versions.

Install rbenv along with ruby-build, the plugin that provides the rbenv install command. Together they let you list, install, and switch between Ruby versions without touching the system Ruby:

brew install rbenv ruby-build

Add rbenv to your shell by appending the init line to your configuration file. This ensures that every new terminal session uses the rbenv-managed Ruby rather than the system one:

echo 'eval "$(rbenv init -)"' >> ~/.zshrc
source ~/.zshrc

Install a recent Ruby version with rbenv. The global command sets the default Ruby for all shells, so you do not need to pick a version manually each time you open a terminal. After the install completes, rbenv rehashes its shims to make the new Ruby available. You can also run rbenv install -l to list all available Ruby versions:

rbenv install 3.4.1
rbenv global 3.4.1

Verify the installation by checking the Ruby version. The output should show the version you just installed rather than the system default. If the version number is wrong, confirm rbenv global is set correctly and that you sourced your shell configuration file:

ruby --version

Method 3: using RVM

RVM (Ruby Version Manager) is another popular option that handles Ruby versions and gem sets comprehensively.

Install RVM by running the bootstrap script. The installer downloads RVM and sets up the shell integration. Sourcing the rvm scripts makes the rvm command available in the current terminal. RVM also manages gemsets, which isolate gem installations per project if you need that level of control:

\curl -sSL https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm

Install Ruby through RVM. The --default flag works like rbenv’s global command, making this Ruby version the one that is active whenever you open a new terminal session. RVM compiles Ruby from source, which may take several minutes on slower machines:

rvm install 3.4.1
rvm use 3.4.1 --default

Ruby installation on Linux

Linux users have several options depending on your distribution.

Ubuntu and Debian

The easiest approach is using rbenv for better version control. Start by installing the build dependencies that Ruby needs to compile from source:

# Install dependencies
sudo apt update
sudo apt install git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libncurses5-dev libffi-dev libgdbm-dev

# Install rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc

# Install ruby-build
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build

# Install Ruby
rbenv install 3.4.1
rbenv global 3.4.1

Fedora

The Ubuntu and Debian instructions use rbenv because it works the same way on every Linux distribution and avoids conflicts with system Ruby packages that other software might depend on. Fedora users who only need a single Ruby version can use the distribution’s package manager directly. The dnf command installs Ruby from Fedora’s official repositories, which is the fastest way to get a working Ruby on that platform without compiling from source.

sudo dnf install ruby ruby-devel

Arch Linux

Fedora’s dnf and Arch’s pacman are the native package managers for those Linux distributions. Both commands install Ruby from the distribution’s package repositories, which is sufficient for getting started quickly. The trade-off with system packages is that they may lag behind the latest Ruby release, since distributions prioritize stability over freshness. If you later need a newer Ruby or want to switch between versions for different projects, switching to rbenv is a straightforward upgrade from either starting point.

sudo pacman -S ruby

Ruby installation on Windows

Windows doesn’t have native Ruby support, but several tools make it straightforward.

Using RubyInstaller

RubyInstaller provides a complete Ruby environment for Windows with just a few clicks:

  1. Download RubyInstaller from rubyinstaller.org
  2. Run the installer
  3. Check “Add Ruby to your PATH”
  4. Complete the installation

After installation, open a new Command Prompt or PowerShell and verify:

ruby --version

Using WSL

For the best experience on Windows, consider using WSL:

The version check confirms that RubyInstaller set up Ruby correctly on your Windows machine. However, some Ruby gems with native C extensions can be difficult to compile on Windows because they expect a Unix-like build environment. Windows Subsystem for Linux provides a full Ubuntu environment inside Windows where Ruby runs exactly as it does on a Linux server. WSL is worth considering if you plan to work with gems that have native extensions, or if your deployment target is a Linux server where you want the development environment to match production.

wsl --install

Once Ubuntu is installed via WSL, follow the Ubuntu installation instructions above. This gives you a full Linux environment where Ruby works natively.

Verifying your installation

Regardless of your operating system, verify Ruby is installed correctly. Running ruby --version confirms the Ruby interpreter is on your PATH and reports the exact version and platform:

ruby --version
# Should output something like: ruby 3.4.1p123 (2026-03-06 revision abc123) [your platform]

irb --version
# Interactive Ruby console version

You should see Ruby 3.x or newer.

Running your first Ruby script

Now that Ruby is installed, let’s write and run your first program:

Create a file called hello.rb with a couple of puts calls. These print lines to standard output, which is the simplest way to confirm Ruby is working. Save the file anywhere convenient; the directory does not matter as long as you run ruby from within it:

# hello.rb
puts "Hello, Ruby!"
puts "Welcome to the Ruby Fundamentals series."

Run the script with the ruby command followed by the filename. Ruby reads the file, executes each statement in order, and prints the results to the terminal. If you see a No such file error, double-check that you are in the same directory as hello.rb:

ruby hello.rb

You should see both greeting lines printed. If the script runs without errors, your Ruby installation is working correctly and you are ready for more substantial programs. This is also a good moment to try a small change, like adding another puts line, to confirm you can edit and rerun scripts easily:

Hello, Ruby!
Welcome to the Ruby Fundamentals series.

Congratulations—you’ve run your first Ruby program. The Kernel#puts reference explains the output method used in the example.

The Ruby ecosystem: gems

Ruby packages are called gems. The RubyGems package manager comes bundled with Ruby and handles downloading, installing, and updating libraries. Verifying it works is a quick first step:

Seeing those greeting lines confirms your Ruby installation is fully working. The next tool to verify is RubyGems, the package manager that ships with Ruby. Every third-party library you add to a Ruby project comes through RubyGems, so making sure it is functional now saves confusion later. The gem --version command confirms that the gem executable is on your PATH and that RubyGems can load its own configuration without errors.

gem --version

RubyGems is already bundled with Ruby, so the gem command should work immediately after installation. If it does not, double-check that your PATH includes the Ruby bin directory.

Installing gems is straightforward with the gem install command. Bundler is a good first gem to add because it manages project-level dependencies, ensuring every developer on a team uses the same gem versions. The Gemfile and Gemfile.lock pattern that Bundler introduces becomes the standard way to declare and pin dependencies in every Ruby project you will work on. Once bundled, bundle exec runs commands inside the project’s gem environment, which prevents accidentally using gems from other projects. This isolation is especially important when different projects need different versions of the same gem.

gem install bundler

Bundler manages gem dependencies for your projects, ensuring consistent environments across different machines.

Choosing your installation method

For most developers, here’s the recommended approach:

  • macOS: Use Homebrew for simplicity, or rbenv if you need multiple Ruby versions
  • Linux: Use rbenv for version flexibility, or your distribution’s package manager for system Ruby
  • Windows: Use RubyInstaller or WSL for the best experience

Now that Ruby is installed, you’re ready to move on to the next tutorial in this series: “Getting Started with Ruby” where you’ll write your first Ruby code and understand the basic syntax.

Troubleshooting

”Ruby not found” error

Ensure Ruby is in your PATH. Check with:

which ruby

If empty, add Ruby to your PATH in your shell configuration file.

Permission denied when installing gems

Never use sudo gem install on macOS or Linux—it can cause permission issues. Instead, either use Homebrew’s Ruby or configure a user gem directory.

Version conflicts

If you have multiple Ruby installations, rbenv or RVM help isolate versions. Use rbenv versions or rvm list to see what’s installed.

Summary

The best Ruby installation method depends on your operating system and how much control you want over versions. Homebrew is simple on macOS, rbenv gives you flexibility on macOS and Linux, RVM is another version manager worth knowing, and RubyInstaller or WSL are the usual choices on Windows.

Whichever method you choose, verify that ruby, irb, and gem run from your terminal. Keeping Ruby separate from the operating system’s own installation makes upgrades and project-specific versions easier to manage.

Installing Ruby is complete once those commands resolve to the interpreter you intended to use.

Next steps

With Ruby installed, you’re ready to explore the language:

  1. Test Ruby in IRB (Interactive Ruby Shell): irb
  2. Explore RubyGems: gem list
  3. Continue to Getting Started with Ruby
  4. Learn dependency management in the Ruby Bundler and gems guide