← Back to Ruby Course | Chapter 1: Setup & Basics | Lesson 4 of 7

Running Scripts

In this page:

  1. Running Scripts

Running Scripts

A Ruby script is run with ruby filename.rb from the command line, executing every statement top to bottom. This is the standard way to run a complete Ruby program, as opposed to experimenting interactively in IRB. The .rb extension is a convention, not a strict requirement.

Note: ruby -c filename.rb checks a script's syntax without actually running it.

Example: Running Scripts

bash
# Run a Ruby script from the command line
ruby hello.rb

# Check syntax without running it
ruby -c hello.rb

⚠️ Run this command in your terminal.

🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.