1. Computing

Using the Command Line

Running and Executing rb Files


Using The Command Line

Before really starting to use Ruby you need to have a basic understanding of the command line. Since most Ruby scripts won't have graphical user interfaces, you'll be running them from the command line. Thus, you'll need to know, at the very least, how to navigate the directory structure and how to use pipe characters (such as |, < and >) to redirect input and output. The commands in this tutorial are the same on Windows, Linux and OS X.

To start a command prompt on Windows, go to Start -> Run. In dialog that appears, enter cmd into the input box and press OK.

To start a command prompt on Ubuntu Linux, go to Applications -> Accessories -> Terminal.

To start a command prompt on OS X, go to Applications -> Utilities -> Terminal.

Once you're at the command line, you'll be presented with a prompt. It's often a single character such as $ or #. The prompt may also contain more information, such as your username or your current directory. To enter a command all you need to do is type in the command and hit the enter key.

The first command to learn is the cd command, which will be used to get to the directory where you keep your Ruby files. The command below will change directory to the \scripts directory. Note that on Windows systems, the backslash character is used to delimit directories but on Linux and OS X, the forward slash character is used.

C:\ruby>cd \scripts

Continue to Running Ruby Scripts.

  1. About.com
  2. Computing
  3. Ruby
  4. Beginning Ruby
  5. Using the Command Line--Running and Executing rb Files

©2014 About.com. All rights reserved.