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.
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.
- Install rbenv and ruby-build:
$ brew install rbenv ruby-build
- Install a Ruby version
$ rbenv install 2.4.0
- 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.