LearnAI ToolsCareerPractice BuildsPlayContact
Lesson 315 min read

Installing Ruby & Running Scripts

Install Ruby with a version manager, use the interactive irb console, run script files, and get familiar with RubyGems.

Introduction

This lesson covers installing Ruby on your system, understanding why most Ruby developers use a version manager rather than a system-wide install, using Ruby's interactive console, and running your first script files.

What You Will Learn
  • How to install Ruby, ideally through a version manager.
  • Why version managers matter more in Ruby's ecosystem than in many others.
  • How to use irb, Ruby's interactive console, for quick experiments.
  • How to run a .rb script file from the command line.

Installing Ruby

# macOS (Homebrew)
brew install ruby
# Ubuntu/Debian
sudo apt install ruby-full
# Windows
# Download the RubyInstaller from rubyinstaller.org

Confirm the install and check your version with a single flag.

ruby -v
Terminal Output

Click Run to see what this code prints.

Why a Version Manager

Most experienced Ruby developers install Ruby through a version manager like rbenv or RVM rather than relying purely on their OS's package manager. This lets you install and switch between multiple Ruby versions per-project — important since different Rails or Gem versions (lesson 11) often expect specific Ruby versions.

# macOS (Homebrew), using rbenv
brew install rbenv
rbenv install 3.3.0
rbenv global 3.3.0

The Interactive irb Console

Running irb opens Ruby's interactive console (Interactive Ruby), perfect for quick experiments without creating a file.

irb
Interactive Session

Click Run to see what this code prints.

Running a Script File

For anything beyond a one-liner, save your code in a file with a .rb extension and pass it to the ruby interpreter.

# greet.rb
name = "World"
puts "Hello, #{name}!"
ruby greet.rb
Terminal Output

Click Run to see what this code prints.

That #{name} syntax is string interpolation — embedding an expression's value directly inside a double-quoted string, one of the first pieces of idiomatic Ruby syntax you'll use constantly starting in the very next lesson.

RubyGems: A First Look

RubyGems is Ruby's built-in package manager — it ships with Ruby itself, no separate install required, and lets you install third-party libraries ("gems") with a single command.

gem install colorize
Terminal Output

Click Run to see what this code prints.

Common Mistakes

Avoid These Mistakes
  • Installing gems that require a specific Ruby version without a version manager, then fighting confusing conflicts across projects.
  • Confusing irb (Ruby's console) with ruby (the interpreter used to run script files) — you'll use both, for different purposes.
  • Forgetting the # (not // or --) for single-line comments — a common early mistake coming from C-family languages.

Best Practices

  • Install Ruby through rbenv or RVM rather than relying solely on your OS's default system Ruby.
  • Confirm your active Ruby version with ruby -v before assuming a specific newer syntax feature is available.
  • Keep irb open while learning — Ruby's fast startup makes it ideal for quick experiments alongside a script file.

Frequently Asked Questions

No — every example in this course uses only Ruby's built-in standard library. Bundler (lesson 11) is introduced once you start managing real project dependencies.

Both are Ruby version managers solving the same core problem — rbenv is lighter-weight and does one thing well; RVM is older and includes more built-in features. Either is a reasonable choice.

Often yes, but frequently an older version not intended for active development — installing your own version through a manager like rbenv is still the recommended approach.

Key Takeaways

  • Ruby installs through your OS package manager, though a version manager like rbenv is the more common real-world approach.
  • irb opens an interactive console for quick experiments.
  • A .rb script file runs with ruby filename.rb from the command line.
  • RubyGems ships with Ruby itself and installs third-party libraries with gem install.

Summary

You now have a working Ruby installation, know how to run both quick experiments and full script files, and have seen how gems get installed. Next, you'll dig into Ruby's variables and its dynamically typed set of data types.

Next Lesson →

Variables & Data Types