How to Install and Run Ruby on Mac OS X - dummies

How to Install and Run Ruby on Mac OS X

By Christopher Haupt

The following instructions for installing Ruby have been tested on Mac OS X Yosemite (10.10.4). They should work fine with Mac OS X El Capitan (10.11.1) or Mavericks (10.9.5) as long as you’re running the latest updates for that version of Mac OS X:

1Open the Applications folder, and then open the Utilities folder.

Locate the terminal program in the Utilities folder.

2Open the terminal application.

You see a prompt indicator that looks like a dollar sign ($). In the terminal application, you type commands and press the Return key to get things done. Typing commands is a low-level way of working with a computer. Before the mouse and graphical interface was invented, this was the only way to tell the computer what to do!

Note that your default prompt will include information like the name of your computer, the directory you’re in, and even who you’re logged in as:

Christophers-MacBook-Pro:~ chaupt$

3Mac OS X comes with a version of Ruby preinstalled; check the version by typing ruby --version at the command prompt:

$ ruby --version
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]

In this example, the version of Ruby is 2.0.0, and the number following the letter p is the current patch or build number. Newer versions of Ruby are available, and the Mac’s version will change if you install updates.

4To use some of the Ruby gems (little add-on enhancements for Ruby), you must install Apple's command-line programming tools.

These tools are a part of the free Xcode development tools package that Apple makes available. In the terminal, enter the following command:

$ xcode-select --install

5Press Return.

The program will open a window to confirm you want to install the tools.

6Click the Install button, agree to the license, and wait for the tools to get set up.

This step will take a few minutes depending on the speed of your Internet connection.

7Install a set of software installation tools called Homebrew.

Homebrew makes it easy to install and update additional software, called packages. Homebrew makes it much easier to get everything working. In your browser, go to the Homebrew website.

You see instructions for installing Homebrew. The page shows a really long command that starts with ruby -e. You can copy it from the web page and paste it into your terminal window at the prompt.

This is one long line, so if something goes wrong, make sure that you got the whole thing.

The command uses Ruby to install the Homebrew tool. It displays a warning about using sudo and then asks you for your password to finish the installation.

8Proceed with the installation.

Many progress messages will fly by on your screen. If you get a message saying that you haven’t agreed to the Xcode license, follow the instructions that are displayed and continue on here.

9Once Homebrew installation is done, check that all is okay.

Type the following command:

$ brew doctor

If everything is set up properly, you should see a message saying Your system is ready to brew. Otherwise, you may have some instructions to follow to finish updating Homebrew.

Homebrew’s purpose is to make installing low-level software easier.

10Install some of the libraries of code you need for future projects.

Type the following command:

$ brew install sdl2 libogg libvorbis

11Press Return.

You see a series of progress reports as Homebrew installs the software.

12Install the Gosu gem.

Enter the following command to install Gosu:

$ sudo gem install gosu

Ruby installs the gem and should provide a confirmation message.

You need to use sudo here because when you install a Ruby gem, you install it for the entire system to use. Remember to take care when entering the command — you’re giving it special permissions using the sudo program.