How to Install, Set Up, And Get Started Coding With The Ruby Programming Language - On macOS

A List For 2025

By Rob Rockwell

Ruby is a dynamic, expressive programming language designed for clarity and developer happiness. Popularized by the Ruby on Rails framework, it’s a favorite among developers for web development, scripting, and automation tasks. With its elegant syntax and supportive community, Ruby remains a reliable and enjoyable language to work with on macOS.

This guide will walk you through installing Ruby on macOS, including how to use version managers like rbenv or RVM to handle multiple Ruby versions. You’ll also learn how to configure your system to manage gems and dependencies with Bundler. Whether you’re crafting quick scripts or building full-scale web applications, Ruby is simple to get started with on your Mac.

Retro Mainframe Smiling Guy Install Ruby

Ruby Prerequisites

macOS comes with a system version of Ruby pre-installed, but it's often outdated and should not be modified. For development purposes, it’s best to install and manage your own version using a tool like rbenv or RVM.

Before installing Ruby, ensure you have the Xcode Command Line Tools installed. These include compilers and other tools needed to build Ruby from source.

Installing Ruby

There are a few ways to install Ruby on macOS, but the most reliable and flexible method is through a version manager like rbenv or RVM (see below). However, if you want to install Ruby system-wide via Homebrew (not recommended for managing multiple versions), you can do:

brew install ruby

This installs the latest Ruby version via Homebrew, but be aware that you may need to update your shell configuration to include the correct path for Homebrew Ruby:

echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zprofile

Using rbenv or RVM for Version Management

If you’re doing serious Ruby development, you’ll want to install and manage Ruby versions using rbenv or RVM. Both tools allow you to install multiple versions of Ruby and switch between them easily.

To install rbenv and ruby-build using Homebrew:

brew install rbenv ruby-build rbenv init 

Then add the following to your shell config (e.g., ~/.zshrc or ~/.bash_profile):

eval "$(rbenv init -)"

Now restart your terminal or source your shell file:

source ~/.zshrc # or source ~/.bash_profile

Then install Ruby:

rbenv install 3.2.2 rbenv global 3.2.2

Alternatively, you can install RVM instead:

\curl -sSL https://get.rvm.io | bash -s stable --ruby

Both tools are widely used, but rbenv tends to be simpler and easier to integrate with Homebrew on macOS.

Verifying Your Installation

Once Ruby is installed, you can confirm the version by running:

ruby -v

This should return the Ruby version you installed, such as ruby 3.2.2. If it doesn't, make sure your shell environment is configured properly for rbenv or RVM to take precedence over the system Ruby.

Setting Up Gems and Bundler

Ruby uses a package manager called gem to install libraries. The most common tool for managing project dependencies is bundler.

You can install Bundler with:

gem install bundler

This command installs the bundler gem globally. If you're using rbenv, make sure to run rbenv rehash afterward to make the new command available:

rbenv rehash

Using IRB (Interactive Ruby)

IRB is Ruby’s built-in interactive shell, great for testing small snippets of code or exploring the language in real-time.

To open IRB, simply type:

irb

You’ll enter a prompt where you can type Ruby code and immediately see the output. To exit, type exit or press Ctrl+D.

Writing Your First Ruby Script

Once Ruby is installed and working, you can write your first script. Open your preferred text editor and create a new file called hello.rb. Add the following code:

puts "Hello, Ruby world!"

Save the file, then open your terminal, navigate to the file’s directory, and run the script with:

ruby hello.rb

You should see Hello, Ruby world! printed in your terminal. Congratulations—you’ve just run your first Ruby script on macOS!

Configuring Your Editor or IDE

For editing Ruby code, lightweight editors like Visual Studio Code, TextMate, or Sublime Text are popular choices on macOS. If you prefer a full-featured IDE, RubyMine offers powerful Ruby and Rails support.

In Visual Studio Code, install the “Ruby” extension by Peng Lv, which adds syntax highlighting, IntelliSense, code navigation, and integrated terminal support. Consider also adding the “Solargraph” gem for code completion and static analysis:

gem install solargraph

Then, configure your editor to use it or let the extension prompt you to enable it. This setup gives you a smooth and modern Ruby development experience on macOS.

Creating a Basic Ruby Project

To create a basic Ruby project on macOS, start by making a new directory and navigating into it from the terminal:

mkdir my_ruby_project cd my_ruby_project

Next, create a Gemfile to define your project’s dependencies, even if it’s just for future expansion. Here's a minimal example:


source "https://rubygems.org"
gem "rake"

Install Bundler if you haven't yet:

gem install bundler

Then run:

bundle install

This sets up your development environment. You can now create source files like main.rb and start coding.

Next Steps and Learning Resources

Once you’re comfortable writing basic scripts and managing gems, explore more advanced Ruby topics like object-oriented programming, modules, and exception handling. Consider building a CLI tool or a web scraper as a learning project.

For deeper learning, the official Ruby Documentation is a great starting point. Other excellent resources include the book “The Well-Grounded Rubyist”, interactive tutorials like RubyMonk, and full courses on platforms like Codecademy and Udemy. Once you're ready, try diving into Ruby on Rails for web development.

Enroll in our revolutionary Code Visualization course!