Search⌘ K
AI Features

Ruby on Windows

Explore the process of installing Ruby on a Windows system, setting up environment variables, and running Ruby scripts through the command prompt. Understand how to create and save Ruby files properly and verify your installation to start programming with Ruby on Windows efficiently.

Overview

In this lesson, you'll learn to set up the environment for Ruby and run Ruby code in Windows OS.

Setup for Windows environment

Installation steps

  1. Download the latest installer from Ruby Installer for Windows and run it.

  2. Select the checkbox for "Add Ruby executables to your PATH" on the installation dialog window.

  1. Keep the defaults for the rest and complete the installation.

In case, you do not tick the "Add Ruby executables to your PATH" checkbox during installation, you can also set up the environment variable after installation manually by using the following command:

set PATH=%PATH%;C:\Ruby200-x64\bin
Setup Windows environment PATH variable

Create and save code file

  • Create a Ruby file ending with the .rb extension and save it on your system.

  • We suggest creating a dedicated folder to put all your code in, for example, C:\Users\you\rubycode.

Command line

The windows that accepts user command (without using a mouse) are called console or command prompt windows.

To start a command prompt on windows platform:

  1. Click “Start.”

  2. Click “All Programs.”

  3. Click “Accessories.”

  4. Click “Command Prompt.”

A window will pop up similar to the following one:

Type the command ruby -v and press "enter" to check the installed version of Ruby. If you get output similar to the following, this means Ruby is installed successfully, and is ready to use.

Execution

To run the program, open a command line and change the directory to the folder containing your ruby code, and type the command ruby followed by the file name to run the Ruby program.

cd rubycode
ruby HelloWorld.rb
Run a Ruby program from command line