Quick guide to install ruby on a Mac

Fabio Soares
Wellington Testers
Published in
2 min readSep 22, 2018

First things first, some people know that ruby is already installed on the MacOS. The reason we need to install it is because we can choose a specific version according to the project we're working on. Few things we're going to use:

Homebrew: something you need to install so you can install more stuff easier

Rbenv: the ruby version is important for your project, this helps you manage that

Bundler: ruby is all about gems (software packages), this helps you with that

Take it easy, you’ll know all about it!

Installing homebrew

Copy and paste in the terminal:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

That’s that! First part is done!

Only the first part though

Installing rbenv so you can install ruby

brew install rbenv ruby-build

Note that brew, is your most recently acquired command from homebrew 😉

Load rbenv automatically

When you open your terminal, your Mac will run the default ruby automatically. If you want, and you want, to load rbenv automatically, do:

echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile

And then

source ~/.bash_profile

This will add a command to your bash_profile, which you can also access by:

open ~/.bash_profile

Installing ruby

rbenv install 2.4.3

Setting installed version globally

rbenv global 2.4.3

Double check if the version is all good

ruby -v

Gemfile and bundler

Every ruby project has a Gemfile (no extension) in the root of the project folder. This file usually is something like this:

source 'https://rubygems.org'
gem 'nokogiri'
gem 'rack', '~> 2.0.1'
gem 'rspec'

and you can add gems according to the functionality you need in the project. You can find all the gems here: https://rubygems.org/.

Every time you add a new gem, you use bundler to install it

First you need to install bundler

gem install bundler

Add these lines to your Gemfile to check it works

source 'https://rubygems.org'
gem 'rspec'

Install gems that are on your Gemfile

bundle install

Celebrate

Congrats! You nailed it!

References

https://medium.com/qaninja/instalando-o-ruby-no-macos-435f451b86a8

--

--