Programming With Ruby Episode 2, Getting Started

by Tyler on March 19th, 2009
Programming With Ruby Episode 1, IntroductionProgramming With Ruby Episode 3, Getting Help/Tools


Covered in this episode:

  • Installing Ruby
  • What you will need
  • Hello World! program

Transcript

Hello everybody and welcome to Programming with Ruby Episode 2 – Getting Started. I’m the presenter, as always, Tyler. This is brought to you by manwithcode.com.

This is ruby-lang.org. Go to the downloads section. There are a bunch of links here. If you are on Windows, go to the Ruby One-Click Installer. It is a standard installer, like any other Windows program.

If you are on a Debian variant of Linux (such as Ubuntu). The line:
sudo apt-get install ruby irb rdoc
will get you what you need

If you are on mac OSX, you can install ruby with mac ports via the command:
port install ruby
alternatively you can go to the ruby OSX one click installer (http://rubyosx.rubyforge.org/), be sure to the installer for version 1.8.7 not 1.9.1

If you are compiling from source, compile 1.8.7 NOT 1.9.1

To get started you will need a text editor, like Notepad. It needs to be plain text editor, we don’t want any of the formatting that programs like Word put on there.

My editor of choice is gEdit, which comes with the GNOME desktop on Linux.

Alternatively you can use an IDE, like Netbeans or Geany.

Open up your text editor, and type in:

puts "Hello World!"

save that to your desktop as hello.rb

There are two ways of running this. If you are on Windows, go to where you saved it and double click on it.

Or you can open up the Command Prompt/Terminal. Change directories to where you saved the files and type in:
ruby hello.rb

Questions or Comments
Leave a comment on this page
or email me at tyler@manwithcode.com

Programming With Ruby Episode 1, IntroductionProgramming With Ruby Episode 3, Getting Help/Tools

Be Sociable, Share!

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS

4 Comments
  1. orodos permalink

    tyler:
    you rule, man.

  2. Matt permalink

    hello Tyler,
    after double clicking, my program hello.rb ends quickly without letting me see the content. no problem by command line. why this happens?

    thank you, and truly good luck with the website.

    • This happens because when you just run the program, it’s able to do everything it’s been programmed to do so quickly that it displays the results and exits before you ever get a chance to see the results. Whereas when you run it from the command prompt, it’s output stays in the command prompt window, and that window doesn’t close because it’s waiting for you to run another command. You can make it possible to run your program and see it before it closes by adding “gets” (without quotes) as the last line of your program. Your program will then wait for you to press enter before it closes and you’ll get to see everything it printed out.