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

Running Scripts

A Ruby script is a saved file of instructions that you run with one command. It is like playing a recipe from start to finish.

In this page:

  1. Running Scripts
Syntax
ruby
ruby script_name.rb

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 in your own terminal or Node.js environment.

Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Running ruby hello without .rb when the file is named hello.rb, so Ruby cannot find it.
  2. Running the command from a different folder, so Ruby reports No such file or directory.
  3. Forgetting that ruby -c hello.rb only checks syntax and does not run the code.
🔒

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.