Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Setting up your own Ruby Dev Environment on a Mac

Setting up the Ruby dev environment on a Mac

Tested on Yosemite. Should work on El Cap. Message me if it doesn't.

Why would I want to do that?

  • You are tired of using vagrant
  • You want to run guard
  • You want use Sublime plugins (like RSpec or Guard plugins)
  • You want your code to run faster in development

1. Installing brew

Brew aka Homebrew is a package management system for Mac OSX. You can think of it as a command line version of the App Store.

Open up the Mac Terminal and run this command to install brew on your mac:

ruby -e "$(curl -fsSL"

After brew is done installing run

brew update

1.5 Install coreutils

GNU File, Shell, and Text utilities needed to compile gems.

brew install coreutils

2. Install ruby through rvm

Open a terminal window. Run this command to download an install rvm and the latest version of ruby.

\curl -sSL | bash -s stable --ruby

In the latest version of ruby you might see this error: "Empty path passed to certificates update, functions stack". There is a bug in rvm. Run rvm reinstall 2.5.0 --disable-binary.

Close the current terminal window and open a new one.

rvm list # shows you all the versions of ruby installed on your computer
rvm -h # shows you the help menu with all the commands you can run

3. Install Ruby 2.5.0 and set it as the default version

# Install ruby version 2.5.0
rvm install 2.5.0
# this will take a while... rvm is downloading and installing ruby

# Tell rvm to use 2.5.0 as the default version of ruby
rvm --default use 2.5.0

# Check that you are using the latest version of ruby
ruby -v
# Should show ruby 2.5.0

4. Install rails

Install rails on your system so you can create new rails projects.

gem install rails

And now we can verify Rails is installed:

rails -v
# Rails 4.1.1

5. Install the Postgres database server

Install the server

brew install postgresql

Initialize the database

initdb /usr/local/var/postgres -E utf8

Get postgres to start automatically when your computer starts.

First, figure out which version of postgres was installed by brew.

cd /usr/local/Cellar/postgresql/
# There should be a folder in here with the version number

Then, run the code below, replacing 9.2.1 with your version of postgresql.

mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.2.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist


6. Install the pg gem

gem install pg

Note: This might fail. If it does, ask a TA or add a comment to this gist.

7. Install the command line developer tools

If you have XCode < 5.1.1

The nokogiri gem needs these. See here for details:

xcode-select --install

If you have XCode > 5.1.1

Follow these instructions:

  1. Open XCode
  2. Click on Xcode > Open Developer Tools > More Developers Tools This will take you to the Downloads for Apple Developers web site. Use your AppStore Id to login.
  3. Download Command Line Tools for your Mac OS X version. (Probably Mavericks April / March 2014).

Update Mar 2018: If the above instructions fail follow the instructions here, which should be up to date:

See if it worked

Run the terminal command below. It should successfully install the nokogiri gem (an DOM parsing library).

gem install nokogiri

8. Install the gems for a Rails project

  cd /Users/monica/lighthouse/laser_shark
  bundle install

Follow the other setup instructions for that rails app. For laser_shark, you will have to edit your /etc/hosts, for example.

9. Change database.yml

You will need to update the database connection settings for all your Rails applications. In config/database.yml, make sure you have the following settings for the development and test environments. Of course, replace rotten_mangoes with the name of your rails app.

  adapter: postgresql
  database: rotten_mangoes_development
  host: localhost
  encoding: unicode

  adapter: postgresql
  database: rotten_mangoes_test
  host: localhost
  encoding: unicode

To check if the database connection settings work, see if you can create the database.

bin/rake db:create


Could not connect to server: Connection refused

If you see this error, make sure Postgres database is started.

SYS:laser_shark SYS$ bin/rake db:create
could not connect to server: Connection refused
Is the server running on host "localhost" ( and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (fe80::1) and accepting
TCP/IP connections on port 5432?
/Users/SYS/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/postgresql_adapter.rb:881:in `initialize'

XCode: Can't install software because it's not currently available on your computer

You probably have XCode 5.1.1 or higher and tried to install the command line tools via command line. See Install the command line developer tools section above.

Help Improve this

I wrote this down from memory. If any of the steps here don't work, please fork this gist, fix the issue and share with the class.

Copy link

kvirani commented Jun 22, 2014

Thanks for this @monicao

AFAIK if you using (as this gist suggests) you could remove the username and password fields from the database.yml file entirely.

Also, vagrant uses RVM, and that's what I'm used to using. My understanding is that functionality-wise they achieve the same results. In our vagrant box, we use RVM.

Copy link

eubenesa commented Aug 23, 2014

@monicao @kvirani

I made some additions to the Install the section:

Also, I switched to rbenv from RVM during like W4 of the bootcamp. I find rbenv cleaner, and it seems to play nicer with Zsh / Oh My Zsh. With rbenv, you can set Ruby version globally and locally for an individual project, etc. Just my two cents.

Copy link

astopo commented Sep 2, 2014

Thanks for this Monica! Didn't run into any problems.

Copy link

KazW commented Sep 30, 2014

@monicao @kvirani
I'd recommend avoiding the use of, installing it through brew is less hacky: no pg_config passing and no modification of the database.yml file (works out of the box after rails new). Unix sockets have caused less issues for us since authentication is handled implicitly.

If using brew, why not just do a brew install rvm postgresql? 😃 This is DRYer from a sys-admin perspective and it has a better removal path, isn't something a normal user can do (uninstalling is more complex than deleting the app).

Also, I just open sourced the Foodee Dev-Kit:

Copy link

monicao commented Sep 30, 2014

Thanks for the feedback guys!

I liked the idea of the Postgres App because it's easy to see if the database is started (icon in the task bar).
But I see your guys' point about database.yml... Updating the gist to use brew install postgresql instead.

Copy link

kweestian commented Dec 2, 2014

Copy link

monicao commented Dec 2, 2014

Thanks @kweestian. Updated the gist.

Copy link

kvirani commented Dec 22, 2014

@monicao / @KazW any good writeups / gists on setting up a ruby + pg + git (web dev) env for linux users? Something easy and detailed enough that we can give our Lighthouse "linux" students on Day1 (or even before day1)

I ask b/c we want Windows / Mac users to use vagrant but don't really push it on students with Linux laptops

Copy link

monicao commented Jan 3, 2015

@kvirani This guide looks good to me. The only thing is that they use rbenv.

Copy link

alberlau commented Nov 27, 2020

This helped me to resolve following issue:

Installing io-console 0.5.6 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: /private/var/folders/2m/jvgr860s46qf54r5zm3k8kv00000gp/T/bundler20201126-55841-61jf5fio-console-0.5.6/gems/io-console-0.5.6/ext/io/console

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20201126-55841-1ufmbek.rb extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Provided configuration options:
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in block in try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in with_werror' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:852:in macro_defined?' from extconf.rb:7:in


To see why this extension failed to compile, please check the mkmf.log which can be found here:


extconf failed, exit code 1

Gem files will remain installed in /var/folders/2m/jvgr860s46qf54r5zm3k8kv00000gp/T/bundler20201126-55841-61jf5fio-console-0.5.6/gems/io-console-0.5.6 for inspection.
Results logged to /var/folders/2m/jvgr860s46qf54r5zm3k8kv00000gp/T/bundler20201126-55841-61jf5fio-console-0.5.6/extensions/universal-darwin-19/2.6.0/io-console-0.5.6/gem_make.out

An error occurred while installing io-console (0.5.6), and Bundler cannot continue.
Make sure that gem install io-console -v '0.5.6' --source '' succeeds before bundling.

In Gemfile:
irb was resolved to 1.2.4, which depends on
reline was resolved to 0.1.4, which depends on

I executed the following:

brew update
brew install coreutils
\curl -sSL | bash -s stable --ruby
rvm install 2.6
rvm --default use 2.6.5
ruby -v

Copy link

monicao commented Nov 28, 2020

Thanks for posting this Albert!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment