Search⌘ K
AI Features

Ruby on Mac OS X

Explore how to run Ruby on Mac OS X by utilizing the pre-installed Ruby version. Learn to create and save Ruby files with .rb extensions, navigate the Mac Terminal, and execute your Ruby programs. This lesson helps you manage Ruby coding tasks efficiently on Mac systems.

Overview

In this lesson, you'll learn to run Ruby code in Mac OS X.

Setup Mac OS X

No installation is required as a ready-to-use Ruby version comes with Mac OS X.

Create and save code file

Create a Ruby file ending with the .rb extension and save it to a dedicated folder on your system.

Tip: Creating a dedicated folder is recommended to be more organized.

Command line

  • The application to access the command line in Mac OS X is called Terminal. Open in Finder: Applications → Utilities → Terminal

  • A window will pop up similar to the following:

  • You can check the installed version of Ruby by using ruby -v in the terminal.

Execution

To run the program, you can use ruby, followed by the file name with the .rb extension, and then hit enter.

For example, to execute the HelloWorld.rb file, you write ruby HelloWorld.rb.