How to Install Ruby

short and concise way to install ruby on windows and linux

How to Install Ruby

How to Install Ruby Programming Language on Windows

Ruby is a dynamic, object-oriented programming language known for its simplicity and productivity. Installing Ruby on Windows has become much easier over the years, with several reliable methods available. This guide will walk you through the most effective ways to get Ruby up and running on your Windows system.

Prerequisites

Before installing Ruby, ensure your Windows system meets these requirements:

  • Windows 10 or Windows 11 (64-bit recommended)
  • At least 500 MB of free disk space
  • Administrator privileges for installation
  • Stable internet connection for downloading files

RubyInstaller is the easiest and most popular way to install Ruby on Windows. It provides a complete Ruby development environment with minimal configuration required.

Step 1: Download RubyInstaller

  1. Visit the official RubyInstaller website: rubyinstaller.org
  2. Navigate to the Downloads section
  3. Choose the latest stable version with DevKit (e.g., “Ruby+Devkit 3.2.x (x64)”)
  4. Download the installer file (approximately 150-200 MB)

Step 2: Run the Installer

  1. Locate the downloaded .exe file in your Downloads folder
  2. Right-click the installer and select “Run as administrator”
  3. Follow the installation wizard:
    • Accept the license agreement
    • Choose installation directory (default is usually fine: C:\Ruby32-x64)
    • Select components to install (keep all default selections)
    • Check “Add Ruby executables to your PATH” option

Step 3: Install MSYS2 Development Toolchain

After the main Ruby installation completes:

  1. The installer will prompt you to install MSYS2
  2. Press Enter to proceed with the recommended installation
  3. This will install the development toolchain needed for native gem compilation
  4. The process may take several minutes to complete

Step 4: Verify Installation

Open Command Prompt or PowerShell and run:

ruby --version

You should see output similar to:

ruby 3.2.0 (2022-12-25 revision a528908271) [x64-mingw-ucrt]

Also verify gem installation:

gem --version

Method 2: Using Windows Subsystem for Linux (WSL)

WSL provides a Linux environment within Windows, offering a more Unix-like Ruby development experience.

Step 1: Enable WSL

  1. Open PowerShell as Administrator
  2. Run the following command:

    wsl --install
    
  3. Restart your computer when prompted

Step 2: Install Ruby in WSL

  1. Open your WSL terminal (Ubuntu by default)
  2. Update package lists:

    sudo apt update
    
  3. Install Ruby and development tools:

    sudo apt install ruby-full build-essential
    

Step 3: Verify WSL Installation

Check Ruby version in WSL:

ruby --version
gem --version

Method 3: Using Package Managers

Using Chocolatey

If you have Chocolatey installed:

  1. Open PowerShell as Administrator
  2. Install Ruby:

    choco install ruby
    

Using Scoop

If you prefer Scoop:

  1. Open PowerShell
  2. Install Ruby:

    scoop install ruby
    

Post-Installation Configuration

Setting Up Bundler

Bundler is essential for managing Ruby gem dependencies:

gem install bundler

Configuring Git (Optional)

If you plan to work with Ruby projects from Git repositories:

  1. Download and install Git from git-scm.com
  2. Configure your Git username and email:

    git config --global user.name "Your Name"
    git config --global user.email "your.email@example.com"
    

Installing a Code Editor

Consider installing a Ruby-friendly code editor:

  • Visual Studio Code: Free, with excellent Ruby extensions
  • RubyMine: Professional IDE specifically for Ruby development
  • Sublime Text: Lightweight with good Ruby syntax support

Testing Your Ruby Installation

Create a simple Ruby script to test your installation:

  1. Create a new file called hello.rb
  2. Add the following content:

    puts "Hello, Ruby World!"
    puts "Ruby version: #{RUBY_VERSION}"
    puts "Platform: #{RUBY_PLATFORM}"
    
  3. Run the script:

    ruby hello.rb
    

Common Issues and Troubleshooting

Ruby Command Not Found

If you receive a “command not found” error:

  1. Restart your command prompt or PowerShell
  2. Verify Ruby is in your PATH environment variable
  3. Reinstall Ruby ensuring the “Add to PATH” option is checked

SSL Certificate Issues

If you encounter SSL errors when installing gems:

gem update --system

Or download the SSL certificate manually:

gem install --http-proxy http://proxy.server:port gem_name

Native Extension Build Failures

Ensure you have the DevKit installed (included with RubyInstaller). For manual installation:

  1. Download DevKit from RubyInstaller website
  2. Extract to a permanent location
  3. Initialize and install:

    cd path/to/devkit
    ruby dk.rb init
    ruby dk.rb install
    

Version Management with rbenv-win

For managing multiple Ruby versions, consider using rbenv-win:

  1. Install from GitHub repository
  2. Use commands like:

    rbenv install 3.2.0
    rbenv global 3.2.0
    rbenv local 2.7.0
    

Best Practices

Keep Ruby Updated

Regularly update Ruby and gems:

gem update --system
gem update

Use Version Control

Always use a .ruby-version file in your projects to specify the Ruby version:

3.2.0

Gemfile Management

Use Gemfiles for dependency management:

source 'https://rubygems.org'

gem 'rails', '~> 7.0'
gem 'sqlite3', '~> 1.4'

Conclusion

Installing Ruby on Windows is straightforward with the right tools. RubyInstaller remains the most beginner-friendly option, providing everything needed for Ruby development in a single package. For developers seeking a more Unix-like environment, WSL offers excellent compatibility with Ruby and its ecosystem.

Once installed, you’ll have access to Ruby’s powerful features and the vast RubyGems ecosystem. Whether you’re building web applications with Rails, automation scripts, or exploring Ruby’s elegant syntax, you now have a solid foundation to start your Ruby programming journey on Windows.

Remember to keep your Ruby installation updated and explore the rich ecosystem of gems available through RubyGems. Happy coding!