Tutorials  /  Linux Basics

How to Install Ruby and Set Up a Local Programming Environment on macOS

Ccentron Redaktion · January 2025 ·5 min read ·Linux Basics, Tutorial

Ruby is a dynamic programming language you can use to write anything from simple scripts to games and web applications. It was first released in Japan in 1993, but gained popularity in 2005 as a language for server-side web development. Ruby is designed to be easy to use and fun for beginners, but powerful enough to create complex systems. It’s a great choice for beginners and experienced developers alike.

Ruby is already included in a default macOS installation, although it won’t be the most recent version. You may run into compatibility issues when following tutorials or attempting to use other projects if you use it.

In this tutorial, you’ll set up a Ruby programming environment on your local macOS machine using Homebrew, and you’ll test your environment out by writing a simple Ruby program.

Prerequisites

You will need a macOS computer running El Capitan or higher with administrative access and an internet connection.

VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access start at €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

Step 1 — Using the macOS Terminal

You’ll use the command line interface (CLI) to install Ruby and run various commands related to developing Ruby applications. The command line is a non-graphical way to interact with your computer. Instead of clicking buttons with your mouse, you’ll type commands as text and receive text-based feedback. The command line, also known as a shell, lets you automate many tasks you do on your computer daily, and is an essential tool for software developers.

To access the CLI, you’ll use the Terminal application provided by macOS. Like any other application, you can find it by going into Finder, navigating to the Applications folder, and then into the Utilities folder. From here, double-click the Terminal application to open it up. Alternatively, you can use Spotlight by holding down the COMMAND key and pressing SPACE to find Terminal by typing it out in the box that appears.

macOS Terminal

If you’d like to get comfortable using the command line, take a look at An Introduction to the Linux Terminal. The CLI on macOS is very similar, and the concepts in that tutorial are directly applicable.

Now that you have the Terminal running, let’s install some prerequisites you’ll need for Ruby.

Step 2 — Installing Xcode’s Command Line Tools

Xcode is an integrated development environment (IDE) that is comprised of software development tools for macOS. You won’t need Xcode to write Ruby programs, but Ruby and some of its components will rely on Xcode’s Command Line Tools package.

Execute this command in the Terminal to download and install these components:

Code
xcode-select --install

You’ll be prompted to start the installation, and then prompted again to accept a software license. Then the tools will download and install automatically.

Step 3 — Installing and Setting Up Homebrew

While the CLI on macOS has a lot of the functionality you’d find in Linux and other Unix systems, it does not ship with a good package manager. A package manager is a collection of software tools that work to automate software installations, configurations, and upgrades.

To install Homebrew, type this command into your Terminal window:

Code
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Step 4 — Installing Ruby

With Homebrew installed, install Ruby with the following command:

Code
brew install ruby

To check the version of Ruby that you installed, type:

Code
ruby -v

Step 5 — Creating a Program

Create a file called hello.rb:

Code
nano hello.rb

Type the following code into the file:

Code
puts "Hello, World!"

Run the program:

Code
ruby hello.rb

Conclusion

This small program proves that you have a working development environment. You can use this environment to continue exploring Ruby and build larger, more interesting projects.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Linux Basics
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren