Installing Ruby on Your System
Before we can use Rails, we need to install Ruby. The best way to manage Ruby versions is using a version manager like rbenv or rvm.
Installing on macOS
Step 1: Install Homebrew (if not already installed)
Homebrew is the package manager for macOS. Open Terminal and run:
bash
1/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Step 2: Install rbenv
rbenv lets you easily switch between multiple Ruby versions:
bash
1# Install rbenv and ruby-build
2brew install rbenv ruby-build
3
4# Add rbenv to your shell
5echo 'eval "$(rbenv init - zsh)"' >> ~/.zshrc
6
7# Reload your shell
8source ~/.zshrcStep 3: Install Ruby
Now install the latest Ruby version:
bash
1# List available Ruby versions
2rbenv install -l
3
4# Install Ruby 3.3.0 (or latest stable)
5rbenv install 3.3.0
6
7# Set it as the global default
8rbenv global 3.3.0
9
10# Verify installation
11ruby -v
12# Output: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]Installing on Ubuntu/Debian Linux
Step 1: Install dependencies
bash
1sudo apt update
2sudo apt install -y git curl libssl-dev libreadline-dev zlib1g-dev \
3 autoconf bison build-essential libyaml-dev libreadline-dev \
4 libncurses5-dev libffi-dev libgdbm-devStep 2: Install rbenv
bash
1# Clone rbenv
2git clone https://github.com/rbenv/rbenv.git ~/.rbenv
3
4# Add to PATH
5echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
6echo 'eval "$(rbenv init - bash)"' >> ~/.bashrc
7source ~/.bashrc
8
9# Install ruby-build plugin
10git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-buildStep 3: Install Ruby
bash
1rbenv install 3.3.0
2rbenv global 3.3.0
3ruby -vInstalling on Windows
For Windows, we recommend using WSL2 (Windows Subsystem for Linux):
Step 1: Enable WSL2
Open PowerShell as Administrator:
powershell
1wsl --installStep 2: Install Ubuntu from Microsoft Store
After restarting, install Ubuntu from the Microsoft Store, then follow the Linux instructions above.
Verifying Your Installation
Run these commands to verify everything is working:
bash
1# Check Ruby version
2ruby -v
3
4# Check gem (Ruby's package manager)
5gem -v
6
7# Check bundler (manages gem dependencies)
8gem install bundler
9bundler -vCommon Issues and Fixes
Permission errors with gems
Never use sudo to install gems. If you get permission errors:
bash
1# Check that rbenv is properly configured
2which ruby
3# Should show: /Users/yourname/.rbenv/shims/ruby
4
5# If not, reinitialize rbenv
6rbenv init
7source ~/.zshrc # or ~/.bashrcOpenSSL errors
If you see SSL certificate errors:
bash
1# macOS
2brew install openssl
3RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl)" rbenv install 3.3.0You're now ready to install Rails and create your first application!
