How to Execute Ruby Script in Windows?
Last Updated :
13 May, 2024
Ruby is a dynamic, object-oriented programming language and a Ruby script is a plain text file containing code written in the Ruby programming language. Ruby scripts are saved with a .rb extension. Ruby scripts can be used to write programs as simple as "Hello, World!", to complex applications, such as web servers, automation scripts, or data processing tools.
To execute the Ruby Script in Windows, you need to make sure that Ruby is installed in the system and that its path is added to the system's environment variables.
Check if Ruby is installed and the path is added to the environment variable by typing this command in your command prompt or Powershell:
ruby -v
Output should look like this, version number can differ in your system so do not worry about it:

In case any other output or error shows then read this article to install and set up it: How to install Ruby on Windows?
Ways to execute Ruby Scripts in Windows
In Windows, you can execute Ruby scripts using various methods but these are the most common:
- Using Command Prompt or Powershell
- Using Ruby Interactive Shell (IRB)
Using Command Prompt or Powershell
Create a file with any name and save it with ".rb" extension and write your ruby script in that file then open the Command Prompt or Powershell and locate it to the directory where you saved your Ruby Script.
Here in this example, we are executing "test.rb" script:
Ruby
puts "Hello Geeks"
puts "How are you?"
This up here is our ruby script and it can be executed with the command "ruby filename.rb", in our case its "ruby test.rb":

Using Ruby Interactive Shell (IRB)
The Ruby Interactive Shell, usually referred to as IRB (Interactive Ruby), is a command-line tool that allows you to interactively execute Ruby code. It provides a REPL (Read-Eval-Print Loop) environment where you can type Ruby code, and it will be executed immediately, displaying the results back to you.
You can start an IRB in your Command Prompt or Powershell just by typing "irb":

You can execute code directly in Ruby Interactive Shell like this:

You can even run the Ruby Script file directly in Ruby interactive shell by loading it with load command:

Similar Reads
How to Install SQLite3 for Ruby on Windows? SQLite is one type of SQL database engine. It is mainly written in the C programming language. It is built with a C programming library. SQLite is used basically in mobile applications & some computer applications. It is widely used for database purposes. As it is a stable application database i
2 min read
How to Run an EXE through CMD in Windows Running software in Windows is usually as simple as double-clicking a .exe file. But what if you want to launch an executable using the Command Prompt (CMD)? Whether for automation, troubleshooting, or scripting, CMD offers a powerful way to run .exe files directly from the terminal.In this guide, w
6 min read
How to Install Ruby Bundler on Windows? Ruby is a high-level and open-source programming language. It is very useful in many aspects. Like other programming languages, Ruby is nowadays a highly useful programming language. Bundler is a type of environment manager in Ruby. It is generally used to install and update correct Gems for Ruby. G
2 min read
How to install Ruby on Windows? Prerequisite: Ruby Programming Language Before we start with the installation of Ruby on Windows, we must have first-hand knowledge of what Ruby is?. Ruby is a pure Object-Oriented language developed by Yukihiro Matsumoto (also known as Matz in the Ruby community) in the mid-1990s in Japan. Everythi
2 min read
How to execute shell command in Ruby? Ruby is also known for its simplicity and versatile nature, it provides various methods for executing shell commands within your scripts. Whether you need to interact with the underlying operating system or automate tasks, Ruby offers several approaches to seamlessly integrate shell commands into yo
3 min read
How to install RubyGems in Windows? RubyGems is a Ruby package manager that provides Ruby programs and libraries (also known as Gems) and the tools associated with installing and managing Ruby packages and servers. The Ruby package management, RubyGems, makes it simple to install, manage, and utilize tools and libraries for Ruby appli
3 min read