Installing Ruby and Using IRB
Before writing any Ruby code, you need a working Ruby installation and a way to experiment quickly. Most developers install Ruby through a version manager rather than a system package manager, because Ruby projects frequently pin specific versions, and a version manager lets you switch between them without conflicts. Once Ruby is installed, IRB (Interactive Ruby), Ruby's built-in read-eval-print loop (REPL), lets you type expressions and see results immediately, making it an essential tool for learning the language and debugging small snippets.
Cricket analogy: Before you can face a delivery in a match you need proper kit fitted to your height, and a net session lets you try shots quickly; Ruby install is the kit, IRB is the net session for testing shots before the real innings.
Choosing a Version Manager
The two most common Ruby version managers are rbenv and RVM. rbenv is lightweight and does one thing well: it manages which Ruby version is active per shell or per directory, delegating actual installation to the ruby-build plugin. RVM is older and more feature-rich, also managing gemsets, but is heavier. A newer, faster option gaining popularity is mise (formerly rtx), which manages multiple language runtimes including Ruby. Whichever you choose, avoid relying solely on the OS-bundled Ruby, since it is often outdated and modifying it can break system tools that depend on it.
Cricket analogy: Choosing rbenv over RVM is like a franchise picking a lean specialist bowling coach who focuses only on line and length versus a full support staff that also handles fitness and diet, both valid but different scopes.
# Typical installation flow using rbenv (run in a terminal, not IRB)
# $ rbenv install 3.3.0
# $ rbenv global 3.3.0
# $ ruby -v
# => ruby 3.3.0 (2023-12-25 revision xxxx) [x86_64-linux]
# Starting IRB from the terminal:
# $ irb
# irb(main):001:0> 2 + 2
# => 4
# irb(main):002:0> "ruby".capitalize
# => "Ruby"Working Effectively in IRB
IRB evaluates each line you enter and prints its return value, prefixed with =>. This makes it ideal for testing method behavior, exploring an unfamiliar object's API, or checking how a piece of syntax parses. You can inspect an object's available methods with .methods, check its class with .class, and load an external file with load or require_relative. Modern Ruby (3.0+) ships an improved IRB with multiline editing, autocomplete, and colorized output, making it far more pleasant than earlier versions.
Cricket analogy: IRB showing => after each line is like a scoreboard instantly updating after every ball, letting you check a player's stats or the match state on demand, the way .methods or .class reveal an object's full profile.
IRB is Ruby's equivalent of Python's interactive shell or Node's REPL. A more feature-rich alternative, Pry, adds syntax highlighting, a powerful debugger, and object introspection tools, and many Ruby developers install it as a drop-in replacement for daily work.
Pasting multi-line code with existing indentation into IRB can sometimes trigger confusing parse states, especially in older IRB versions. If IRB seems 'stuck' waiting for more input, type end or press Ctrl+C to reset the prompt.
- Use a version manager like rbenv, RVM, or mise instead of relying on the OS-bundled Ruby.
- rbenv pairs with the ruby-build plugin to install and switch Ruby versions per project.
- Run
ruby -vto confirm your active Ruby version after installation. - IRB is Ruby's built-in REPL, launched by typing
irbin a terminal. - IRB prints each expression's return value with a
=>prefix, making it great for quick experimentation. - Pry is a popular enhanced alternative to IRB with better introspection and debugging tools.
Practice what you learned
1. Why do most Ruby developers use a version manager instead of the OS-bundled Ruby?
2. What command starts Ruby's interactive REPL?
3. What plugin does rbenv rely on to actually install Ruby versions?
4. In IRB, what does the `=>` prefix before output indicate?
5. Which tool is a popular enhanced alternative to IRB?
Was this page helpful?
You May Also Like
What Is Ruby?
An introduction to Ruby's history, design philosophy, and the traits that make it a productive, expressive, object-oriented programming language.
Hello World and Ruby Syntax
Write your first Ruby program and learn the fundamental syntax conventions: statements, indentation, method calls, and file structure.
Bundler and Gems
Understand how RubyGems packages and distributes Ruby libraries, and how Bundler locks dependency versions with a Gemfile and Gemfile.lock for reproducible builds.
Ruby Quick Reference
A condensed cheat sheet of core Ruby syntax, common Enumerable methods, and idioms for fast lookup while coding.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics