Installing Ruby

Like Java, you will need at most only two pieces of software: the Ruby environment and some text editor. Depending on your operating system, you'll use different instructions to install Ruby.

Windows
Mac OSX
Linux

If you encounter problems trying to set up Ruby, contact us for help and suggestions.

Windows

Windows does not come with Ruby pre-installed, so you will have to download and install it.

Step 1. Install Ruby

Ruby v1.8.6 One-Click Installer

Click the link above to download the Ruby installer. Once downloaded, run the program to install Ruby. If there is an option, include RubyGems in the installation. RubyGems will be necessary for Rails installation.

Step 2. Install TextPad

TextPad Download

After installing Ruby, you will want a text editor. Like the rest of the course, we recommend TextPad. Download TextPad (txpeng520.exe) from the link above. Run the .exe to install it.

Step 3. Configure Textpad to Run Ruby Programs (Optional)

Those of you who would like to run Ruby programs from the command line, please skip to the next step.

Otherwise, you can configure Textpad to run Ruby programs. After you have successfully installed Ruby:

  1. Open Textpad
  2. At the top, click 'Configure' -> 'Preferences'
  3. In the selection tree on the left, at the very bottom, click on 'Tools'
  4. At the top right, click 'Add' -> 'Program'
  5. Navigate to the path of your Ruby interpreter, and select ruby.exe. Again, in my case it is installed at C:\ruby\bin\ruby.exe
  6. Click 'Open'. You should now be taken back to the 'Tools' section and see 'Ruby' listed
  7. Again, in the selection tree on the left, expand the 'Tools' header. Select the 'Ruby' branch. Uncheck the 'Capture output' and 'Close DOS window on exit'
  8. Click 'OK' to save the changes

Now, open a .rb file in Textpad (like hello_world.rb). To run it, click Tools -> External Tools -> Ruby. You can also use that shortcut (likely something like 'Ctrl + 1'). The output should show up in a console.

Step 4. Ruby Syntax Highlighting in Textpad (Optional)

You may also want to add Ruby syntax highlighting

  1. Download ruby.syn and save it in the "Samples" subdirectory in your Textpad installation folder. For example, on my machine, Textpad is installed at "C:\Program Files\TextPad 5", so I save ruby.syn in "C:\Program Files\TextPad 5\Samples".
  2. Open Textpade. Click "Configure" -> "New Document Class..."
  3. Enter "Ruby" and click "Next"
  4. For "Class Names", enter "*.rb" and click "Next"
  5. Check "Enable Highlighting" and select "ruby.syn" from the "Syntax Definition File" dropdown list and click "Next", then click "Finish"

Step 5. Iteractive Ruby

You can run Interactive Ruby to test Ruby functionality. When you installed Ruby, it came with a program called "fxri". This runs a program that allows you to use Iteractive Ruby without using the console. To use it, Click Start -> Programs -> Ruby and click on 'fxri'.

Step 6. Run Ruby Programs from the Command Line (Optional)

To run a Ruby program from the command line, you just need to call the Ruby interpreter with the path to your Ruby file as and argument. For example, if I open up a command line and I want to run my hello_world.rb program in C:\Documents, just type "ruby C:\Documents\hello_world.rb"

If you want to run Iteractive Ruby from the console, just open a terminal and type 'irb' without any arguments.

Warning: If, after installation, you get the error: " 'ruby' is not recognized as an internal or external command, operable program or batch file " you may need to add Ruby to your Path. To do this, do the following.

Windows XP

  1. Right-click on 'My Computer', then click on 'Properties'
  2. In the 'Advanced' tab, select 'Environment Variables'
  3. Under the 'System Variables' section, scroll and and find 'Path'
  4. Select 'Path' and click 'Edit'
  5. Add the path to your ruby.exe file. Mine is in C:\ruby\bin, so I would add "; C:\ruby\bin"
  6. Click 'OK', and click 'OK' again.

Try running your Ruby program again.

Windows Vista

  1. Click 'Start' -> 'Control Panel'
  2. On the left, click 'Advance System Settings'
  3. Under the 'Advanced Tab' select 'Environment Variables'
  4. Under the 'System Variables' section, scroll and and find 'Path'
  5. Select 'Path' and click 'Edit'
  6. Add the path to your ruby.exe file. Mine is in C:\ruby\bin, so I would add "; C:\ruby\bin"
  7. Click 'OK', Click 'OK' again and close your Control Panel.

Try running your Ruby program again.


Mac OS X

Ruby is probably already installed on your Mac. You can check by opening a Terminal and typing 'irb'. If you already have Ruby installed, this will pull up a Interactive Ruby console.

If Ruby is not installed, you can follow the directions on the Ruby Download page under the "Ruby on OS X".

Additionally, OS X 10.4 ships with a broken version of Ruby. To fix this, follow the directions at http://hivelogic.com/articles/view/ruby-rails-mongrel-mysql-osx


Linux

If you're using a Linux distribution you probably have Ruby already. To check, open a Terminal (aka Command Line) and type 'irb'. If you already have Ruby installed, this will pull up a Interactive Ruby console; otherwise, follow the instructions on the Ruby Download page under the "Ruby on Linux" section.

Valid XHTML 1.1 Valid CSS! JavaScript Lint