Thursday, August 16, 2012

How to run a ruby script

Windows users:

1. Install ruby

goto , then to the Ruby on Windows section and download and install the One-Click Installer.

2. Some scripts can be run simply by clicking on them (this is rare, though).

3. Running scripts from the command prompt

Often scripts want some kind of input or can give useful output. In this case you want to run them from the command line.  See this page on the command prompt in 15 minutes for an overview.
When you have navigated to the directory with the ruby script in it (use the commands cd and dir to get there), you are ready to run your script.  Just type:

ruby myscript.rb

Depending on how windows and ruby has been configured, you may also be able to just type


Many scripts expect an argument (like a filename) after the script name.  If it does, give it the appropriate argument like this:

myscript.rb filename

Ubuntu/Debian users:

To get it, open a terminal and type:

sudo apt-get install ruby irb ri

Make sure the script is executable:

chmod +x myscript.rb

To run the script:


No comments: