Codementor Events

3 Steps to Set up a Ruby Environment on macOS

Published Apr 10, 2017
3 Steps to Set up a Ruby Environment on macOS

MacOS comes pre-installed with Ruby. In fact, if you run ruby -v on your terminal, it will point you to the pre-installed version. However, if you're developing in Ruby, be it core Ruby or web frameworks such as Rails or Sinatra, you will most definitely encounter applications running on different versions of Ruby.

This is where Ruby version manager, such as rvm or rbenv, comes in.

In this tutorial, we'll use rbenv as our Ruby version manager. I find it easier and more intuitive than rvm.

Rbenv intercepts Ruby commands using shims (lightweight libraries that intercept API calls) injected in the PATH, determines which Ruby version is specified by your application, and passes the command along to the correct version.

Installation

We'll use Homebrew to install rbenv.
We'll also install ruby-build, a rbenv plugin, that provides rbenv install command to compile and install different Ruby versions on Unix-like systems.

  1. Install rbenv and ruby-build:
 $ brew install rbenv ruby-build
  1. Install a Ruby version
 $ rbenv install 2.4.0
  1. Set the global Ruby version
 $ rbenv global 2.4.0

Wrapping it up

That's it! We're ready to start developing with Ruby in three simple steps.
You might also want to go through other rbenv commands and run rbenv help. Alternatively, checkout the rbenv readme.

Discover and read more posts from Kabiru Mwenja
get started