Learn how to install a Ruby distribution on windows and set up your first hello world in Ruby for windows.

How to install Ruby on Windows and set up a basic hello world

Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax (similar to Python syntax) that is natural to read and easy to write.

In this article, you'll learn how to setup the development environment of Ruby in Windows easily.

Download a Ruby distribution for windows

You'll need to install a Ruby distribution for Windows in your system. You can download the most recent version not in the official website, but in rubyinstaller.org in the downloads area. This is a self-contained Windows-based installer that includes the Ruby language, an execution environment, important documentation, and more.

Download ruby homepage

If you don’t know what version to install and you’re getting started with Ruby, we recommend you use Ruby 2.2.X installers. These provide a stable language and a extensive list of packages (gems) that are compatible and updated. However, not all packages (gems) are maintained. Some older packages may not be compatible with newer versions of Ruby and RubyInstaller.

Install the distribution

Now execute the installer and proceed with the installation of Ruby for windows as you usually do with any installer.

However, in the Installation Destination and Optional tasks do not forget to check all three options in order to use ruby easily on your computer.

Ruby installation path and optional tasks

Proceed to install and wait till the wizard finishes.

Ruby setup finished

Finally you'll be able to run Ruby code and use its tools in Windows easily !

Hello world

You can execute Ruby code now in your computer, so let's write some code. Before continue, check in your command prompt (cmd.exe) if you've succesfully installed ruby executing the following command on it:

ruby -v

The environment variable ruby should be available everywhere in your console, and the previous command should output something similar (with the version of your distribution) in the console:

Console ruby cmd.exe

Now get started with your Hello World in Ruby, create a file named hello.rb wherever you want. In this case we are going to create a folder in the Desktop with the name ruby and we are going to save the hello.rb file inside.

The previously created file will contain the following code:

puts 'Hello world ! The date and time now is : ' + Time.now.strftime("%d/%m/%Y %H:%M")

To execute a ruby file, you only need to do "ruby path-to-the-file-and-filename" and you're ready to go. As mentioned previously, in this example the file will be located in the ruby folder in the desktop, so you can navigate to the folder using console commands and then execute the file:

cd C:\Users\sdkca\Desktop\ruby
ruby hello.rb

Or just provide the absolute path of the file as second parameter:

ruby C:\Users\sdkca\Desktop\ruby\hello.rb

And the output of the console will be:

Ruby console output

And that's all, simple isn't? Now that you're able to execute Ruby code in your machine, we recommend you to visit the "Give Ruby a Try in your browser" website, to get familiar with the most simple tasks that this programming language have to offer you. Have fun !


Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Sponsors