Running Ruby

Test to see whether Ruby is running on your computer by typing the following at a shell or command prompt:

ruby --version

An affirmative response will look similar to this (this example is for version 1.8.6 running on Mac OS X):

ruby 1.8.6 (2007-03-13 patchlevel 0) [powerpc-darwin8.9.0]

You can install Ruby on any of the major platforms. For Ruby file archives and installation instructions, see

Running the Ruby Interpreter


ruby [switches] [--] [program filename] [arguments]

Switches (or command-line options):


Specify a record separator (\0 if no argument).


Autosplit mode with -n or -p (splits $_ into $F).


Check syntax only.


cd to directory before executing your script or program.


Set debugging flags (set predefined variable $DEBUG to true).

-e 'command'

Execute one line of script. Several -es allowed. Omit [program filename].


split( ) pattern for autosplit (-a).


Edit ARGV files in place (make backup if extension supplied).


Specify $LOAD_PATH (predefined variable) directory; may be used more than once.


Specify the character set. See Table 16.


Enable line-ending processing.


Assume 'while gets( ); ... end' loop around your script.


Assume loop like -n but print line also like sed.


Require the library before executing your script.


Enable some switch parsing for switches after script name.


Look for the script using PATH environment variable.


Turn on tainting checks. ...

Get Ruby Pocket Reference now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.