How to install Ruby and Rails on OS X using rbenv

I recently re-installed Ruby and Rails to start playing with it again. This time when I went to rubyonrails.org to check what was the latest version of Ruby and Rails, I noticed they were not recommending the traditional RVM to manage the Ruby installation anymore, but they were recommending something called rbenv. So I tried it.

Although rbenv has a lengthy documentation page on its GitHub page, the instructions to install Ruby and then Rails where not 100% complete and I had to look for extra information on Stack Overflow and other sites.

Here’s a step by step to install rbenv, Ruby and then Rails on OS X Yosemite.

  1. Install Homebrew, the package manager for OS X. Paste the following at a Terminal prompt:
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Now that Homebrew is installed, run the following:
    $ brew update
    $ brew install rbenv ruby-build
  3. You can now list all the available Ruby version and check the one you want to install:
    $ rbenv install -l
  4. Let’s install Ruby version 2.2.2 (or whatever version you want):
    $ rbenv install 2.2.2
  5. If you check your Ruby version now ($ ruby -v) you will still see the existing system Ruby version and not the one you just installed. To fix that, run the following commands to make sure rbenv is in your PATH:
    $ export PATH="$HOME/.rbenv/bin:$PATH"
    $ eval "$(rbenv init -)"
    $ env | grep PATH
  6. Now that we have rbenv and Ruby installed, let’s install Rails:
    gem install rails
  7. Rails is now installed, but in order for us to use the rails executable, we need to tell rbenv to see it:
    rbenv rehash
  8. And now we can verify Rails is installed:
    rails -v

With that, you should be all set up with your new Ruby on Rails installation.

If you have any questions about any of the steps, just let me know!

Leave a Reply