Ruby Logo

Ruby Installation & Setup

Learn how to install Ruby on different operating systems and set up your development environment.

Home Ruby Ruby Installation & Setup

Ruby Installation & Setup

Get Ruby up and running on your system with the best practices for version management and development environment setup.

System Requirements

Minimum Requirements

  • Operating System: Windows 10+, macOS 10.14+, or Linux (Ubuntu 18.04+, CentOS 7+)
  • Memory: 1GB RAM minimum (2GB+ recommended for development)
  • Disk Space: 200MB for Ruby installation + 500MB for development tools
  • Internet: Required for downloading Ruby and gems

Recommended Setup

  • Memory: 4GB+ RAM for comfortable development
  • Storage: SSD recommended for faster gem installation
  • Ruby Version: Ruby 3.2+ (latest stable)
  • Version Manager: rbenv (recommended) or RVM

Installation Methods

macOS Installation

Method 1: Using Homebrew (Recommended)
# Install Homebrew (if not already installed)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install Ruby
brew install ruby

# Verify installation
ruby --version
Method 2: Using rbenv (Version Management)
# Install rbenv
brew install rbenv ruby-build

# Add rbenv to your shell
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
source ~/.zshrc

# Install latest Ruby
rbenv install 3.2.2
rbenv global 3.2.2

Linux Installation

Ubuntu/Debian
# Update package list
sudo apt update

# Install Ruby and development tools
sudo apt install ruby-full build-essential

# Verify installation
ruby --version
CentOS/RHEL/Fedora
# Install Ruby and development tools
sudo dnf install ruby ruby-devel

# Or for older systems
sudo yum install ruby ruby-devel

Windows Installation

Method 1: RubyInstaller (Recommended)
  1. Visit rubyinstaller.org
  2. Download Ruby+Devkit 3.2.x (x64) installer
  3. Run the installer and follow the setup wizard
  4. Choose "MSYS2 and MINGW development toolchain" when prompted
  5. Open Command Prompt and verify: ruby --version
Method 2: Using Chocolatey
# Install Chocolatey (if not already installed)
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

# Install Ruby
choco install ruby

Verify Installation & PATH

# Check versions
ruby -v
gem -v
bundler -v

# Which Ruby is being used?
which ruby # macOS/Linux
where ruby # Windows (cmd)

If you use rbenv, ensure your shell loads it (e.g., add eval "$(rbenv init -)" to your shell rc file and restart the terminal).

Editor & Tooling Recommendations

  • Install a modern editor (e.g., VS Code or RubyMine) and enable Ruby LSP for autocomplete and navigation.
  • Install RuboCop for code style and linting; run rubocop -a to auto-fix common issues.
  • Use a terminal with persistent history; consider setting up a project folder for your exercises.

Troubleshooting (Common Issues)

  • OpenSSL errors (macOS): Install OpenSSL with Homebrew and ensure it’s linked as needed.
  • Build tools (Linux): Install build-essential, libssl-dev, and related headers for compiling Ruby and gems.
  • Windows devkit: When using RubyInstaller, select “MSYS2 and MINGW toolchain” to avoid native gem build failures.
  • WSL (Windows): For a Linux-like environment, use WSL and follow Linux install steps inside your distro.

Version Management

Why Use a Version Manager?

Version managers allow you to install and switch between multiple Ruby versions, which is essential for working on different projects that may require different Ruby versions.

rbenv (Recommended)

rbenv is a lightweight Ruby version management tool that's simple, fast, and doesn't interfere with your shell.

Installation & Usage
# Install rbenv
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash

# List available Ruby versions
rbenv install --list

# Install a specific Ruby version
rbenv install 3.2.2

# Set global Ruby version
rbenv global 3.2.2

# Set local Ruby version for a project
rbenv local 3.1.4

RVM (Ruby Version Manager)

RVM is a comprehensive Ruby environment management tool that provides more features but is heavier than rbenv.

Installation & Usage
# Install RVM
curl -sSL https://get.rvm.io | bash -s stable

# Reload shell
source ~/.rvm/scripts/rvm

# List available Ruby versions
rvm list known

# Install and use a Ruby version
rvm install 3.2.2
rvm use 3.2.2 --default

Verification & Next Steps

Verify Your Installation

# Check Ruby version
ruby --version
# Should output: ruby 3.2.2p... (or similar)

# Check RubyGems version
gem --version

# Test Ruby with a simple command
ruby -e "puts 'Hello, Ruby!'"

If you see version numbers and "Hello, Ruby!" output, your installation is successful!

Next Steps

  1. Install Bundler: gem install bundler
  2. Learn IRB: Start the Interactive Ruby shell with irb
  3. Write Your First Program: Create a simple Ruby script
  4. Explore Ruby Documentation: Learn how to find help and documentation

Common Issues & Troubleshooting

"Command not found: ruby"

Cause: Ruby is not in your system PATH.

Solution: Restart your terminal, or add Ruby to your PATH manually. If using rbenv, make sure you've run rbenv init.

"Permission denied" errors

Cause: Trying to install gems system-wide without proper permissions.

Solution: Use a version manager (rbenv/RVM) or install gems with --user-install flag.

Outdated Ruby version

Cause: System package manager installed an older Ruby version.

Solution: Use a version manager to install the latest Ruby version, or update your system packages.

Quick Navigation

Related Topics

Video Tutorial

Watch and learn ruby installation & setup

Pro Tip: After reading through the content above, watch this video to reinforce your understanding and see the concepts in action!