Programming Tutorials

Getting started with Ruby on rails

By: Emiley J. in Ruby Tutorials on 2008-10-03  

First of all you have to check whether Ruby is already installed in your computer. To do that you can follow these steps.

Ruby runs on Windows 2000, Windows XP, or later; Mac OS X; and any version of Unix you're likely to find. You may already have Ruby installed on your machine. To find out, type this at the command

prompt:

prompt> ruby -v

If you see a complaint like "command not found," you'll have to install Ruby.

If Ruby is installed, the response will look something like this:

ruby 1.8.1 (2003-12-25) [powerpc-darwin]

Installing Ruby

in Windows

There is a one-click Ruby installer. You can find it here: http://www.ruby-lang.org/en/downloads/. After you download it, double-click it in Windows Explorer to run it, and then follow the directions. After installing Ruby, close any command-line windows, open a new one, and then follow the directions above to check the installation.

in Mac OS X

Tiger (version 10.4) and later versions of Mac OS X come with recent enough versions of Ruby. If you're using an older release of OS X, see http://www.ruby-lang.org/en/downloads/

Other Unix Variants

You may be able to find precompiled versions of Ruby (RPMs, etc.) in the usual places and retrieve them via the usual tools (apt-get, pkg-get, ports, etc.).

Your Two Basic Tools to use Ruby on rails

There are two basic tools: an editor and an interpreter.

Your Editor

You can use any editor that works with text files to create Ruby scripts. On Windows, I recommend you use SciTE, which is installed with Ruby. It's more than just a text editor: it understands Ruby well enough to color-code parts of a script to make it easier to read, and it lets you run scripts without having to switch to the command line. (In the Start menu's Programs entry, you'll find a Ruby entry, and SciTE is under that.)

On a Mac, I recommend TextMate (http://macromates.com/). It costs money, but you can try a free download. On the Mac and other Unix-like systems, you can use pico. It's free. Start it by typing its name at the command prompt. It shows its available editing commands at the bottom of the screen. In that help,

Control + X is denoted by ˆX.

If you use the Gnome window system on Linux, gedit is worth trying.

irb

The second useful tool is irb. It lets you try your ideas without having to write a whole script. You can type a little snippet of Ruby and quickly check what it does. Now check that irb is ready for use. At the command prompt, type the following. (Remember not to include the prompt.)

prompt> irb

You'll see something like this:

irb(main):001:0>

Most of the pieces of the prompt are unimportant. Now type a Ruby expression, and press Enter (on Windows) or Return (on Unix-like systems):

irb(main):001:0> 1+1

=> 2

irb(main):002:0>

irb displays the result and then prompts you to type something more. 2 is the result of evaluating the expression 1+1.

Exit from irb like this:

irb(main):003:0> exit

prompt>






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Ruby )

Latest Articles (in Ruby)