Install Ruby and Rails

Before you write your first line of Rails code, you need Ruby and Rails installed on your computer. This topic walks you through the complete setup process for Windows, macOS, and Linux.

Follow the steps in order. Each step depends on the one before it.

What You Are Installing

Think of the installation like setting up a kitchen before cooking:

Your Computer
    |
    +-- Ruby (the cooking stove)
    |       -- The language that powers everything
    |
    +-- RubyGems (the spice rack)
    |       -- Comes with Ruby; manages packages
    |
    +-- Bundler (the recipe book manager)
    |       -- Keeps your project's packages organized
    |
    +-- Rails (the full kitchen setup)
            -- The web framework built on top of Ruby

Step 1: Install a Ruby Version Manager

A version manager lets you install multiple Ruby versions and switch between them. This matters because different projects may need different Ruby versions.

On macOS and Linux — Use rbenv

Open your terminal and run:

curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash

Then add rbenv to your shell:

echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc

If you use macOS with zsh (default on newer Macs), replace .bashrc with .zshrc.

On Windows — Use RubyInstaller

Download the RubyInstaller from rubyinstaller.org. Choose the version marked Ruby+Devkit. Run the installer and check the box to install the MSYS2 toolkit when prompted. This toolkit provides the build tools Windows needs.

Step 2: Install Ruby

macOS and Linux

Install Ruby 3.2 (or the latest stable version) using rbenv:

rbenv install 3.2.2
rbenv global 3.2.2

Confirm Ruby is installed:

ruby -v

You should see something like: ruby 3.2.2 (2023-03-30)

Windows

After running the installer, open a new Command Prompt and check:

ruby -v

Step 3: Install Bundler

Bundler manages the libraries your Rails project uses. Install it with:

gem install bundler

RubyGems (the package system) comes bundled with Ruby. The gem install command downloads packages from the internet.

Step 4: Install Node.js and Yarn

Rails uses JavaScript tools to process CSS and JavaScript files. Node.js and Yarn power this process.

macOS

brew install node yarn

If you don't have Homebrew, install it first from brew.sh.

Linux (Ubuntu/Debian)

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g yarn

Windows

Download and install Node.js from nodejs.org. Then install Yarn:

npm install -g yarn

Step 5: Install Rails

Now install the Rails gem:

gem install rails

This downloads Rails and all its dependencies. It takes a minute or two. Confirm the installation:

rails -v

You should see something like: Rails 7.1.0

Step 6: Install a Database

Rails needs a database to store your app's data. For beginners, SQLite3 is the easiest choice — it requires no separate server setup.

macOS

SQLite3 is usually pre-installed. Check with:

sqlite3 --version

Linux

sudo apt-get install sqlite3 libsqlite3-dev

Windows

SQLite3 is included with the Ruby+Devkit installer. No additional steps needed.

Verify Everything Works

Run all four checks in your terminal:

ruby -v       # Should show Ruby version
rails -v      # Should show Rails version
node -v       # Should show Node.js version
yarn -v       # Should show Yarn version

If all four commands return version numbers, your environment is ready.

Common Installation Problems

ProblemLikely CauseFix
Command not found: rubyShell did not reload after rbenv setupRun source ~/.bashrc or restart terminal
gem install failsPermission error on macOS/LinuxNever use sudo with gem install when using rbenv
rails -v shows old versionMultiple Ruby versions on machineRun rbenv global 3.2.2 and reinstall Rails
Node not found on WindowsPATH not updated after Node installRestart Command Prompt after installing Node

Using a Text Editor

You need a code editor to write Rails code. Visual Studio Code is free, fast, and works on all platforms. Download it from code.visualstudio.com. Install the Ruby and Rails extensions from the VS Code marketplace for syntax highlighting and code suggestions.

Once your environment is ready, you move on to creating your first Rails application in the next topic.

Leave a Comment

Your email address will not be published. Required fields are marked *