Skip to main content

Write and Execute your first Ruby program using Windows Command Prompt

Follow below steps to run your first program in Ruby:

Step 1: We already installed Ruby in our previous video. Now, to verify you can type following command in terminal:

$ ruby -v

This will return the version of ruby installed on your system. 

Step 2: Locate your project directory or navigate to your desired location. To create new directory, type mkdir followed by directory name

$ mkdir rubydemo
$ cd rubydemo

Step 3: Type below command to create file using notepad

$ notepad hello.rb

Step 4: In notepad file add following code and save the file with hello.rb , here hello is my filename and .rb is it's extension.

puts "Hello World!"

Here like Java we don't need to use public static void main and brackets. We just need to type Hello World in double quotes. The puts method is then followed by a sequence of characters — Hello, World!, enclosed in quotation marks. Any characters that are inside of quotation marks are called a string. The puts method will print this string to the screen when the program runs.

Step 5: Execute the code by typing below command, here hello.rb is our file name 

$ ruby hello.rb

Running the ruby command launched the Ruby interpreter. The Ruby interpreter read the file you specified and evaluated its contents.

Submitted by tgoswami on June 12, 2021

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.