TExcelTAD
Home › Ruby › Ruby Get Started

Ruby Get Started

You can follow this whole course without installing anything — every playground runs real Ruby for you. Sooner or later, though, you will want Ruby on your own computer to write scripts and projects. This lesson shows how to install it, how to run a .rb file, and how to experiment with the interactive console, irb.

Check whether Ruby is installed

Open a terminal and ask Ruby for its version:

bash · try it yourself
ruby -v
ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-linux]

If you see a version number of 3.x, you are ready. If the command is not found, or the version is very old (macOS used to ship Ruby 2.6 for its own tools), install a fresh one.

Installing Ruby

System Recommended way
Windows RubyInstaller (rubyinstaller.org) — choose the "with Devkit" download
macOS Homebrew: brew install ruby, or a version manager
Linux Your package manager (sudo apt install ruby-full) or a version manager
Any system A version manager such as rbenv, asdf or chruby + ruby-install

A version manager lets you keep several Ruby versions side by side and pick one per project. Professional Ruby developers almost always use one, because different projects often need different versions.

bash
# Example with rbenv
rbenv install 3.4.7
rbenv global 3.4.7
ruby -v

Note: Ruby comes with RubyGems (the gem command) and Bundler built in. You will meet them in the Gems & Bundler lesson.

Your first script file

Create a file named hello.rb in any text editor (VS Code with the Ruby LSP extension is a popular choice):

ruby · try it yourself
name = "Ada"
puts "Hello, #{name}!"
puts "Ruby is running version #{RUBY_VERSION[0, 3]}"
Hello, Ada!
Ruby is running version 3.4

Then run it from the terminal with the ruby command followed by the file name:

bash · try it yourself
ruby hello.rb
Hello, Ada!
Ruby is running version 3.4

RUBY_VERSION is a built-in constant holding the interpreter version as a string. [0, 3] takes the first three characters.

One-liners with -e

For a quick calculation you don't even need a file. The -e flag runs the code you type:

bash · try it yourself
ruby -e 'puts 60 * 60 * 24'
86400

The interactive console: irb

irb (Interactive Ruby) is a REPL: you type an expression, press Enter, and immediately see its value after =>. It is perfect for trying out a method before using it in a program.

bash · try it yourself
irb
irb(main):001> 2 + 3
=> 5
irb(main):002> "banana".reverse
=> "ananab"
irb(main):003> [3, 1, 2].sort
=> [1, 2, 3]
irb(main):004> puts "hi"
hi
=> nil
irb(main):005> exit
irb(main):001> 2 + 3
=> 5
irb(main):002> "banana".reverse
=> "ananab"
irb(main):003> [3, 1, 2].sort
=> [1, 2, 3]
irb(main):004> puts "hi"
hi
=> nil
irb(main):005> exit

Notice the last example: puts prints hi, but the value it returns is nil. irb always shows the return value of each expression — a useful reminder that in Ruby every expression produces a value.

irb trick What it does
_ The value of the previous expression
Tab Auto-completes method and variable names
"text".methods.sort Lists everything you can call on a string
help / show_doc String#split Shows documentation
exit or Ctrl+D Leaves irb

Ruby runs top to bottom

A Ruby file is executed line by line. A method must be defined before the line that calls it runs:

ruby · try it yourself
def greet(who)
  "Welcome, #{who}!"
end

puts greet("Lin")
puts greet("Sam")
Welcome, Lin!
Welcome, Sam!

Tip: In this course, whenever you see a ```ruby run block, you can edit it and run it right here. Code that only makes sense in a real terminal (installing gems, starting servers) is shown with its expected output instead.

Test yourself

Which command runs a Ruby file named app.rb?

  1. run app.rb
  2. ruby app.rb
  3. irb app.rb --run
  4. gem app.rb

In irb, what does => nil after puts "hi" mean?

  1. The print failed
  2. puts returns nil after printing
  3. The string was empty
  4. irb is waiting for more input

Why do developers use a version manager like rbenv?

  1. To make Ruby run faster
  2. To keep several Ruby versions and choose one per project
  3. To install Rails automatically
  4. To compile Ruby to machine code