Home » How to Install Ruby on Mac

How to Install Ruby on Mac

by Online Tutorials Library

How to Install Ruby on MacOS

Introduction

Ruby is a dynamic, reflective, general purpose, object oriented programming language developed by Yukihiro “Matz” Matsumoto in Japan. It is a multiple paradigm language developed in mid-1990. It was influenced by Perl, SmallTalk, ADA and LISP.

In this tutorial, we are going to learn the installation process of ruby on MacOS through terminal.

Prerequisites

  • MacOS
  • Login as an administrator on terminal.
  • Homebrew must be installed on the system.

Installation

The following steps are involved in installation of Ruby on MacOS.

1) Configuration of third party tools to install Ruby

On MacOS, ruby can be installed with the help of various third-party tools that are rbenv and rvm(ruby version manager). These tools come specifically for MacOS. In order to install ruby on the system, we must have configured either of these two on our MacOS.

To configure rbenv on our MacOS, we use homebrew that can install rbenv on our MacOS.

Let’s see how can this be done.

Macos Ruby 1

This make rbenv all set to install ruby on our MacOS. To check whether rbenv configured on the system or not, type rbenv on the terminal as shown below.

Macos Ruby 2

We got rbenv 1.1.1 installed on our MacOS. When we type rbenv on the terminal, it doesn’t only show the version installed but it also shows all the options and commands which can be done with rbenv including the installation and uninstallation of ruby versions.

2) Install Ruby

Once we have installed rbenv on our system, we can easily install ruby by simply using the command rbenv followed by the version name which we want to install. In our case it will be 2.4.2. We must run rbenv rehash command to rehash shims under rbenv. This has to be run after every new installation.

Macos Ruby 3

3) Setting the default version

we have successfully installed ruby 2.4.2 on our system. To set newly installed ruby 2.4.2 as our default version, we can use global or local option with rbenv. The global set the default version globally while local set the default version locally.

Macos Ruby 4

Now we have successfully installed ruby 2.4.2 and set it to the default on our MacOS.

You may also like