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.
We'll cover the following...
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
Download the latest installer from Ruby Installer for Windows and run it.
Select the checkbox for "Add Ruby executables to your PATH" on the installation dialog window.
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
Create and save code file
Create a Ruby file ending with the
.rbextension 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:
Click “Start.”
Click “All Programs.”
Click “Accessories.”
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 rubycoderuby HelloWorld.rb