File Extension File Extension Guide

What is an RB File?Ruby Code

A guide to the .rb extension, a Ruby source code file. What an RB file holds, why it is plain text you edit yet needs Ruby to run, how the interpreter turns it into a working program, and how to open and run one.

Ruby Source Code 📝 Plain Text 💎 Ruby Language ⚙️ Run With Ruby
.RB

Ruby Source Code

Type:Source code
Extension:.rb
Language:Ruby
Run With:Ruby interpreter
Edit With:Any code editor

📖 What is an RB File?

An RB file is a piece of Ruby code saved as plain text. It holds instructions written in the Ruby programming language, ready to be run by Ruby to do whatever the code describes, from a quick task to a whole application.

The .rb ending simply marks the file as Ruby. Inside is ordinary readable text, the kind you could open in any editor, made up of Ruby statements that tell the computer what to do. Ruby is a general-purpose language, so an RB file might do almost anything, tidy up some files, crunch a batch of data, add a feature to another program, or form part of a website. What it will not do is run just by being opened, because the text spells out instructions instead of being a ready-built program, and something has to read those instructions and carry them out.

That something is the Ruby interpreter, the program that reads an RB file and executes it line by line. So working with an RB file has two sides that are easy to mix up. You edit it as text in a code editor, where you can read and change the Ruby inside, and you run it with Ruby, which turns those written instructions into actual behaviour. Keeping those two ideas apart, editing the code versus running it, explains most of what people find puzzling about these files.

Key Characteristics

  • Ruby source code saved as plain text
  • Readable and editable in any code editor
  • Run by Ruby, not by opening it
  • General-purpose, used for many tasks

Good to Know

  • .rb means the file is written in Ruby
  • Needs the Ruby interpreter to run
  • Text inside, not a compiled program
  • Common in Ruby on Rails websites
💡 Why it matters: An RB file is where a Ruby program lives as readable text. You edit that text to change what the program does, then hand the file to Ruby to actually run it.

⚡ Quick Facts

File Extension.rb
What It IsA Ruby source code file
LanguageRuby
FormatPlain text
Created ByYukihiro Matsumoto
First Released1995
Runs WithThe Ruby interpreter
Edits WithAny code editor

💎 The Ruby Language

Making sense of an RB file is easier with a feel for the language behind it, since Ruby has a character of its own that shapes how the code looks and works.

Ruby is a general-purpose programming language created in Japan by Yukihiro Matsumoto, known as Matz, and first released in 1995. He set out to make a language that programmers would enjoy using, with a clean and readable style that reads almost like plain English in places. It is object-oriented, meaning it treats nearly everything as an object with its own data and actions, and it is an interpreted language, so the code runs directly through Ruby rather than being turned into a separate program first. Ruby is open source and free, and it drew ideas from several earlier languages, which is part of why it feels both familiar and distinctive. That focus on readability and productivity is the reason many people find Ruby a pleasant language to write, and it is why so much Ruby code ends up in these tidy .rb files.

💡 Made to be enjoyed: Ruby was designed for programmer happiness, with a readable style and an object-oriented, interpreted design. That character is what you are looking at inside any RB file.

🔍 What an RB File Holds

Open an RB file in a text editor and you will see plain, readable code rather than anything cryptic. Knowing the usual ingredients makes the content far less mysterious.

A typical RB file is a sequence of Ruby instructions. It often defines methods, which are named blocks of code that perform a task, and it may group related code into classes and modules that model the things the program deals with. There are variables that hold values, and control structures such as loops and conditions that decide what runs and how often. Lines beginning with a hash are comments, notes for humans that Ruby ignores. A small file might be a single short script that does one job, while a large one can be part of a much bigger application built from many RB files working together. Whatever the size, it is all readable text, which is exactly why you edit it in a code editor.

A small example RB file

# greet.rb, a tiny Ruby script
def greet(name)
  puts "Hello, #{name}!"
end

greet("world")   # prints: Hello, world!

⚙️ How Ruby Runs It

The one idea that clears up the most about an RB file is the job of the Ruby interpreter, because it explains why the file needs Ruby at all.

When you run an RB file, the Ruby interpreter reads your code and carries it out directly, step by step, rather than first turning the whole thing into a separate standalone program. This is what it means to call Ruby an interpreted language, and it is why Ruby must be present on the machine for the file to do anything. The upside is that the cycle of writing and testing is quick, since you can change the text and run it again straight away with nothing to build in between. The trade is that an RB file is not self-contained, so handing someone the file alone is not enough unless they also have Ruby installed to read it. In short, the RB file supplies the instructions and Ruby supplies the engine that acts on them.

An RB file has two sides greet.rb Open in a code editor read and change the Ruby code (text) Run with Ruby ruby greet.rb carries out the code Editing changes what it does. Running makes it happen. Both need nothing more than a text editor and the Ruby interpreter

📂 How to Open an RB File

Opening an RB file can mean two different things, reading its code or actually running it, and the tool you reach for depends on which you want.

To read or change the code, open the file in a text editor. A plain editor like Notepad or TextEdit shows the contents, but a dedicated code editor is far nicer, with VS Code, Sublime Text or the Ruby-focused RubyMine colouring the syntax and helping you catch mistakes. That is all you need if your goal is simply to look at or edit what the file does. To actually run the program, you need Ruby itself installed, after which you point Ruby at the file from a terminal. If double-clicking an RB file does nothing useful, that is normal, because your system may not know to hand it to Ruby, and running it from the command line is the reliable way. So for viewing, any editor works, and for running, Ruby is the missing piece.

1

To read the code

Open it in a Ruby-aware editor like VS Code for coloured, readable code.

2

To run the program

Install Ruby, then run the file from a terminal with the ruby command.

3

If double-click fails

That is expected, since the system may not pass the file to Ruby on its own.

▶️ How to Run One

Running an RB file is straightforward once Ruby is installed, and it is the same simple step on every system.

First check that Ruby is present by asking it for its version in a terminal, which also tells you the install worked. To run a script, open a terminal, move to the folder that holds the file, and type the word ruby followed by the file name, after which Ruby reads the file and performs whatever the code says, printing any results into the terminal window. Installing Ruby differs a little by platform, since Windows users typically add it with the RubyInstaller package, macOS already includes a version though many developers manage their own with a version tool, and Linux users install it through the system package manager. Once Ruby is in place, that one short command is all it takes to run any RB file you have.

Running a Ruby script

# check Ruby is installed
ruby -v            # shows the version, e.g. ruby 3.2.0

# run a script in the current folder
ruby greet.rb      # Ruby reads and runs the file

💎 Gems, require and Bundler

Real Ruby programs rarely work alone, and RB files often pull in code that other people have written. Ruby has a tidy system for this that is worth knowing, since it explains a lot of what you see at the top of a file.

A shared Ruby library is called a gem, and gems are published on a central home called RubyGems. You add one to your machine with the gem install command, then bring it into an RB file with the word require at the top, which loads that library so your code can use it. For a whole project, developers usually let a tool called Bundler handle this instead, listing the gems a project needs in a plain file named Gemfile and installing them all at once with bundle install. This keeps everyone on the same versions and avoids the classic problem of code that runs on one machine but not another. So when you open an RB file and see several require lines near the top, those are simply the libraries the file depends on, most of them gems.

How a gem reaches your code RubyGems a gem lives here install Your machine gem now installed require your .rb file code can use the gem For a whole project, Bundler installs every gem in the Gemfile at once

Adding and using a gem

# install a gem from RubyGems
gem install awesome_print

# then use it inside your .rb file
require "awesome_print"

# or list gems in a Gemfile and install together
bundle install

🔢 Managing Ruby Versions

Ruby comes in many versions, and different projects sometimes need different ones, which is why most Ruby developers use a version manager rather than the single Ruby that came with their system.

The two common tools are rbenv and RVM, and both let you install several versions of Ruby side by side and pick which one a given project uses. The reason this matters is that the Ruby bundled with an operating system, often called the system Ruby, is best left untouched, since changing it can upset other parts of the system, and one project may need a newer Ruby than another. A version manager keeps these separate, installing each Ruby in your own space and switching between them automatically, often by reading a small file in the project that names the version to use. For a beginner running a single script this is more than you need, and the plain install is fine, but as soon as you juggle more than one project a version manager saves a lot of confusion.

💡 One project, one Ruby: A version manager like rbenv or RVM lets each project keep its own Ruby version and gems, so upgrading one project does not break another. It is the standard setup once you have more than one thing on the go.

🚀 Making It Runnable

On Mac and Linux you can set things up so an RB file runs on its own, without typing the word ruby in front each time, which is handy for scripts you use often.

The trick has two parts. First you add a special first line to the file, called a shebang, that points to Ruby and tells the system which interpreter should handle the file. Then you mark the file as executable by giving it run permission, after which you can start it directly by its name. With both in place the system reads the shebang, finds Ruby, and runs the script for you. This is the same approach used by other scripting languages, and it turns a plain RB file into something that behaves like a small command of its own. On Windows the idea is a little different, since programs there rely on Ruby being associated with the .rb extension rather than on a shebang line.

⚠️ Ruby still required: A shebang line and run permission let you launch an RB file by name, but they do not remove the need for Ruby. The system still uses the installed interpreter behind the scenes to run the code.

🛤️ RB Files and Rails

Many people first meet RB files through Ruby on Rails, the well-known framework for building websites, so it is worth being clear about how the two relate.

Ruby on Rails is a large toolkit written in Ruby that makes building web applications faster, distributed as a gem, one of the packaged Ruby libraries that Ruby calls gems, and a Rails project is made up of many RB files alongside other kinds of file. Each of those RB files is still just Ruby source code, the same as any other, but they play defined roles within the Rails structure, such as describing data, handling web requests, or setting options. So an RB file is not itself a Rails file, and plenty of Ruby is written with no Rails in sight, yet if you are exploring a Rails site you will find its logic spread across a great many RB files. Understanding that Rails is Ruby code organised in a particular way makes those files far less intimidating when you open them.

🔀 Other Uses of .rb

Nearly every .rb file you meet is Ruby, but a couple of unrelated programs have borrowed the same two letters, which is handy to keep in mind when a file acts strangely.

The main example is Xojo, a tool for building applications that was once called REALbasic, which used .rb for source code written in a form of the BASIC language. To avoid clashing with Ruby, later versions switched to a different extension, but older REALbasic files may still carry .rb. Some Ruby-enabled applications also use RB files as plugins, small scripts that add features, with the 3D modelling program SketchUp being a well-known case where .rb scripts extend what the software can do. These are still Ruby, just serving as add-ons rather than standalone programs. If an RB file will not behave as a Ruby script, it is worth considering that it might be one of these other kinds, and checking where it came from usually settles the question.

❓ Frequently Asked Questions

An RB file is a Ruby source code file, a plain-text file holding instructions written in the Ruby programming language. The .rb ending marks it as Ruby, and inside is ordinary readable code that you can open in any text editor. Because Ruby is a general-purpose language, an RB file might do almost anything, from a small task like tidying files to forming part of a whole website. It does not run merely by being opened, though, because the text lays out instructions and is not a ready-made program. To actually run it you use the Ruby interpreter, which reads the file and carries out the code.

It depends on whether you want to read the code or run the program. To read or edit it, open the file in a text editor, ideally one of the Ruby-aware editors such as RubyMine, VS Code or Sublime Text, which paint the syntax in colour and make the code simpler to follow. That is all you need to look at or change what the file does. To actually run the program, you need Ruby installed, and then you run the file from a terminal by pointing Ruby at it. If double-clicking the file does nothing useful, that is normal, because your system may not know to hand it to Ruby, so running it from the command line is the reliable route.

Once Ruby is installed, you run an RB file from a terminal with a single command. Open a terminal, move to the folder that contains the file, and type the word ruby followed by the file name, for example ruby greet.rb. Ruby then reads the file and does whatever the code describes, showing any output in the terminal. If you are not sure Ruby is installed, asking it for its version in the terminal confirms it and shows which version you have. Installing Ruby itself varies a little by system, with Windows using the RubyInstaller package, macOS including a version already, and Linux offering it through the package manager.

Yes, you need Ruby, because an RB file is source code that the Ruby interpreter has to read and carry out. Without Ruby installed, the file is just text that nothing on your computer knows how to run, even though you can still open and read it in an editor. Installing Ruby is straightforward and free on every major system, and once it is in place any RB file will run with a single command. This is the nature of an interpreted language, where the code is not turned into a standalone program but is run directly by the interpreter each time, so the interpreter must always be present.

Not exactly, though the two are closely related. An RB file is a plain Ruby source code file, while Ruby on Rails is a large framework for building websites that is itself written in Ruby. A Rails project contains many RB files, each one still ordinary Ruby code, but they play particular roles within the Rails structure, such as describing data or handling web requests. So every Rails project is full of RB files, yet an RB file is not automatically a Rails file, and plenty of Ruby is written with no Rails involved at all. In short, Rails is built from Ruby, so its files are RB files, but RB files exist far beyond Rails too.

Not in the usual sense, because an RB file is source code rather than a document or image, so there is nothing to convert it into the way you might turn a picture into another picture. The code inside can of course be reused, copied into other projects, or built upon, and in some cases a Ruby program can be packaged so it runs without the user installing Ruby separately, but that bundles the interpreter with the code rather than changing the file's format. If you simply want to read an RB file, any text editor shows its contents, and if you want to run it, the Ruby interpreter does that. The file itself is meant to stay as Ruby text.

The most common reason is that Ruby is not installed, since an RB file cannot run without the interpreter, so checking for Ruby in a terminal is the first thing to try. If Ruby is present but the script still fails, the file may contain an error in its code, it may depend on extra Ruby libraries that are not installed, or it may expect to be run from a particular folder. Double-clicking often does nothing useful because the system may not pass the file to Ruby on its own, so running it from the command line usually gives a clearer result and shows any error message. It is also worth checking the file really is Ruby, since a few unrelated programs have used the .rb extension.

Yes, Ruby comes with an interactive shell called irb that lets you type Ruby and see the result immediately, with no file to save or run. You start it by typing irb in a terminal, then enter Ruby a line at a time, and each line runs as soon as you press enter, which makes it perfect for trying an idea, testing a small piece of code, or learning the language. It is a companion to RB files rather than a replacement, since anything you want to keep and reuse still belongs in a saved .rb file, but for quick experiments irb saves you the trouble of creating one. Many developers keep an irb session open alongside their editor for exactly this reason.

All three relate to Ruby but serve different purposes. A plain .rb file is ordinary Ruby source code, the kind this guide describes. An .erb file is Embedded Ruby, a template that is mostly text such as HTML with small pieces of Ruby tucked inside special tags, used to build web pages where Ruby fills in the changing parts, and it is common in Ruby on Rails views. An .rbw file is a Ruby script for Windows that runs without opening a console window, which suits small graphical programs where a black terminal box would look out of place. So .rb is the everyday format, .erb is for templates that mix Ruby with text, and .rbw is a Windows variant that stays quiet in the background.

Yes, several websites let you paste Ruby code and run it in your browser, which is handy for trying a short script, sharing a snippet, or learning without setting anything up. These online Ruby environments run the code on their own servers and show you the output, so nothing is installed on your machine. They work well for small, self-contained scripts, but they are less suited to larger programs that need many gems, read files from your computer, or form part of a bigger project, since those depend on a proper local setup. For a quick look at what a piece of Ruby does, an online runner is convenient, while real development is still done with Ruby installed on your own machine.

Installing Ruby depends on your system. On Windows the usual route is the RubyInstaller package, which sets up Ruby and the tools it needs in one step. On macOS a version of Ruby is already present, though many developers install their own so they can control which version they use. On Linux the system package manager provides Ruby, or you can build it yourself. As for which version, a good rule is to use the current stable release unless a specific project tells you otherwise, since newer versions are faster and better supported. If you work on several projects that need different versions, a version manager such as rbenv or RVM lets you install and switch between them cleanly rather than committing to a single one.

Ruby is often recommended for beginners because it was designed to be readable and pleasant to write, so code tends to look close to plain English and the language stays out of your way. That gentle, expressive style makes early progress feel encouraging, and the interactive irb shell lets you try ideas instantly while learning. Ruby is frequently compared with Python, another beginner-friendly language, and both are excellent starting points, with the choice often coming down to what you want to build and which community you find more welcoming. Ruby has particular strength in web development through Ruby on Rails, so if building websites appeals to you, learning Ruby opens a clear and well-trodden path.

Yes, Ruby remains in active use and continues to be developed, with regular new releases that keep it faster and more capable. It is best known for powering websites through the Ruby on Rails framework, and many well-established companies still run large applications built on it, so Ruby skills stay in demand. Beyond web work, Ruby is widely used for automation, scripting, tooling and data tasks, the same everyday jobs that fill so many .rb files. While newer languages have arrived and fashions shift, Ruby has a devoted community, a mature set of libraries, and a clear niche, which together mean the .rb files you meet are far from a thing of the past.

📝 Summary

An RB file is a Ruby source code file, plain readable text holding instructions written in the Ruby programming language, marked by the .rb extension. Ruby is a general-purpose, object-oriented, interpreted language created by Yukihiro Matsumoto, known as Matz, and first released in 1995, designed above all for readable code and programmer productivity. The key thing to understand is that an RB file has two sides, since you edit it as text in a code editor to read or change the Ruby inside, but you run it with the Ruby interpreter, the program that reads the file and carries out its instructions directly. Because Ruby is interpreted, the file is not a standalone program and Ruby must be installed for it to run, which is why handing someone only the file is not enough unless they also have Ruby. A typical RB file defines methods, groups code into classes and modules, uses variables and loops, and marks comments with a hash, and it may be a single short script or one of many files in a large application. To read the code you open the file in any editor, ideally a Ruby-aware editor such as RubyMine or VS Code that colours the syntax, and to run it you install Ruby and type the word ruby followed by the file name in a terminal. On Mac and Linux a shebang line plus run permission let you launch a script by name, though Ruby is still doing the work underneath. Many people meet RB files through Ruby on Rails, the web framework built from a great many RB files, but an RB file is simply Ruby code and exists far beyond Rails. The extension is almost always Ruby, with rare exceptions from the Xojo tool once called REALbasic and from Ruby plugins in programs such as SketchUp.