Skip to content

Ruby on Rails - Installation

To develop web applications with Ruby on Rails, you need to install several key components. This guide covers modern installation practices. As of writing, current stable versions are around Ruby 3.2.x and Rails 7.1.x. Always check the official Ruby and Rails websites for the latest recommended versions.

  • Ruby: The programming language.
  • RubyGems: The package manager for Ruby libraries (gems).
  • Bundler: Manages application-specific gem dependencies.
  • Rails Framework: The Rails gem itself.
  • Node.js and Yarn/npm: For JavaScript asset management (Rails uses tools like esbuild, which often require a JS runtime).
  • A Database System: SQLite is the default for new apps (easy setup). PostgreSQL or MySQL are common for development and production.

Rails comes with the Puma web server by default, suitable for both development and production.

The recommended way to install Ruby and Rails on Windows is using RubyInstaller.

  1. Visit rubyinstaller.org.
  2. Download the recommended Ruby+Devkit installer (e.g., Ruby+Devkit 3.2.x (x64)). The Devkit is crucial for installing gems with native extensions.
  3. Run the installer. Accept the default settings and ensure the “Add Ruby executables to your PATH” option is checked.
  4. After the Ruby installation finishes, a command prompt window will appear asking which components to install. Choose option 1 (MSYS2 base installation) and then 3 (MSYS2 and MINGW development toolchain). This installs necessary tools for compiling gems.

Step 2: Verify Ruby and RubyGems Installation

Section titled “Step 2: Verify Ruby and RubyGems Installation”

Open a new Command Prompt (cmd.exe or PowerShell) and type:

C:\> ruby -v
C:\> gem -v

You should see the installed Ruby version (e.g., ruby 3.2.2p53) and Gem version.

C:\> gem install bundler
C:\> gem install rails

This installs the latest stable version of Rails. The gem install rails command might take a few minutes as it downloads and installs Rails and its many dependency gems. You’ll see output listing the gems being installed.

Section titled “Step 4: Install Node.js and Yarn (Optional but Recommended)”

Modern Rails uses JavaScript extensively. Install Node.js (which includes npm) from nodejs.org. After installing Node.js, you can install Yarn (another package manager often used with Rails) via npm:

C:\> npm install --global yarn
C:\> rails -v

This should output the Rails version, e.g., Rails 7.1.2.

Congratulations! You have successfully installed Ruby on Rails on Windows.

Using a Ruby version manager like rbenv or RVM is highly recommended on Linux and macOS. This guide uses rbenv.

Dependencies vary by distribution. For Debian/Ubuntu:

$ sudo apt update
$ sudo apt install -y git curl libssl-dev libreadline-dev zlib1g-dev autoconf bison build-essential libyaml-dev libreadline-dev libncurses5-dev libffi-dev libgdbm-dev libjemalloc-dev

For Fedora/CentOS/RHEL:

$ sudo dnf install -y git curl autoconf bison gcc-c++ readline-devel zlib-devel openssl-devel libyaml-devel libffi-devel make bzip2 patch
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc # Or ~/.zshrc if using Zsh
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc # Or ~/.zshrc
$ exec $SHELL
$ git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build

Restart your shell or run exec $SHELL for changes to take effect.

List available Ruby versions: rbenv install -l. Then install a recent stable version (e.g., 3.2.2):

$ rbenv install 3.2.2
$ rbenv global 3.2.2 # Set this version as default

Verify:

$ ruby -v
# Expected output: ruby 3.2.2p53 (YYYY-MM-DD revision XXXXXX) [architecture]

Disable documentation installation for gems (optional, speeds up gem installs):

$ echo "gem: --no-document" > ~/.gemrc
$ gem install bundler
$ gem install rails
$ rbenv rehash # Important after installing gems that provide executables

Verify Rails:

$ rails -v
# Expected output: Rails 7.1.2 (or similar latest version)

Install Node.js (e.g., LTS version) and Yarn. Using NodeSource repositories is common on Linux:

# For Debian/Ubuntu (example for Node.js 20.x)
$ curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
$ sudo apt-get install -y nodejs
# Install Yarn globally via npm
$ sudo npm install --global yarn

Refer to Node.js and Yarn documentation for specific instructions for your distribution.

Step 6: Install a Database (Example: PostgreSQL on Ubuntu)

Section titled “Step 6: Install a Database (Example: PostgreSQL on Ubuntu)”
$ sudo apt install postgresql postgresql-contrib libpq-dev
$ sudo -u postgres createuser -s $(whoami) # Creates a PostgreSQL superuser with your Linux username (for easy local dev)

Congratulations! You have successfully installed Ruby on Rails on Linux.

To update the Rails gem for a specific project, navigate to your project directory and run:

$ bundle update rails

To update the globally installed Rails gem (if you installed it outside a project context, less common for project work):

$ gem update rails
$ rbenv rehash # If using rbenv

Installation Verification: Creating Your First Rails App

Section titled “Installation Verification: Creating Your First Rails App”

Let’s create a new Rails application to verify the installation:

$ rails new demo_app

This command will generate a new Rails application in a directory named demo_app. You’ll see a lot of output as Rails creates files and directories, and runs bundle install to install default gems. Output typically includes lines like create app/controllers/application_controller.rb, run bundle install, etc.

Now, navigate into your new application’s directory and start the Rails development server:

$ cd demo_app
$ bin/rails server # or simply 'rails s'

You should see output indicating the Puma web server is starting, similar to: => Booting Puma => Rails 7.1.2 application starting in development => Run bin/rails server —help for more startup options Puma starting in single mode... * Puma version: X.Y.Z (ruby A.B.C-p...) * Min threads: 5, max threads: 5 * Listening on http://localhost:3000 Use Ctrl-C to stop

Open your web browser and navigate to http://localhost:3000.

You should see the default Rails welcome page, often a simple page with a Ruby on Rails logo and information indicating your application is running successfully in development mode. This confirms your Rails installation is working!