Skip to content

Instantly share code, notes, and snippets.

@revans
Last active December 19, 2015 14:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revans/5968949 to your computer and use it in GitHub Desktop.
Save revans/5968949 to your computer and use it in GitHub Desktop.
Instructions for setting up a local machine for Ruby, Rails, Sinatra, etc development.

Ruby & Rails

If you're unfamiliar or looking to get more familiar with Ruby & Rails, then checkout this tutorial and this learning site.

System Setup

Installing Homebrew will make it much easier to install the necessary libraries.

Using Homebrew to install these libraries

Installing Homebrew:

If you plan on using Homebrew to install the necessary libraries for doing Ruby (Rails, Sinatra, Gem, etc) development, then below is a list of commands for how to install the necessary libraries.

As you're install each library, pay attention to the instructions that Homebrew will often write to your terminal screen. Libraries like MySQL, Redis, Memcache, Sqlite, Postgres, etc. will give you additional instructions and commands to be ran within the terminal to complete the setup. You'll want to read those and do what they ask you to do to complete their setup.

  • brew tap homebrew/dupes
  • brew install apple-gcc42
  • brew install openssl
  • brew install readline
  • brew install zlib
  • brew install libxml2
  • brew install libyaml
  • brew install librsvg
  • brew install libiconv
  • brew install git
  • brew install curl
  • brew install wget
  • brew install redis
  • brew install sqlite
  • brew install memcache
  • brew install ack
  • brew install ag
  • brew install zsh # if you use zsh
  • brew install fish # if you use fish
  • brew install bash # if you use bash
  • brew install phantomjs
  • brew install node
  • brew install mysql
  • brew install imagemagick --use-rsvg
  • brew install postgres --no-python

The above can be put into a single command: brew install openssl readline zlib…. but this allows you to easily detect if any of the above won't install.

There will be post-install instructions for completing the following library setups:

  • MySQL
  • Redis
  • Sqlite
  • Memcache
  • Postgres
Homebrew Shell Path

Make sure to update your Shell's Path to look to Homebrew libraries first:

e.g. in your $HOME/.bash_profile file

# Homebrew Path Setup
export PATH=/usr/local/bin:/usr/local/sbin/:$HOME/bin:$PATH
Install NPM (Node Package Manager)
curl https://npmjs.org/install.sh | sh

You'll need to include NPM's path to your Shell's Path:

e.g. in your $HOME/.bash_profile file

# NPM Path Setup
export PATH=$PATH:/usr/local/share/npm/lib/node_modules

Rbenv Setup

Rbenv has a good setup of instructions for installation. Follow these instructions.

Make sure to update your Shell's Path to include the rbenv executable. More info on path setup, specifically #2 through #4 (we'll install a Ruby version down below).

Install the following Rbenv Plugins (make sure you have created a new directory: $HOME/.rbenv/plugins):

Make sure you have restarted your shell exec $SHELL -l (if using bash) and then run the following command: rbenv versions

  1. The you should not get an error like "rbenv command unknown" and
  2. it should say something about system ruby 1.8.7 as the output of the command.

If rbenv is an unknown command, then your Shell Path is probably not properly set.

Rbenv in your Shell's Path

e.g. $HOME/.bash_profile file

# Rbenv Path Setup
export PATH=$HOME/.rbenv/bin:$PATH
eval "$(rbenv init -)"
Bundler Binstubs Path Setup

Bundler is a RubyGem. RubyGems manages Ruby Libraries much like Nodejs' NPM or Homebrew, or Linux's Apt/Apptitude/Yum for libraries. Bundler makes the management of these gems (specifically versioning of libraries and their dependencies) much easier within a Ruby application/library/Gem/etc.

Binstubs will store the dependencies within your project's root directory for easy access. To make it easy to use these vendor dependencies, add the following to your Shell's Path:

e.g. $HOME/.bash_profile file

# Project specific, executable dependencies
export PATH=./bin:$PATH

The command bundle install --binstubs will install the application's dependencies. Application dependencies are set within the Gemfile that is located in the application's root directory. This file should not be altered in anyway, unless you really know what you're doing. Changing dependency versions, adding new dependencies, deleting dependencies, etc. can result in the application failing to run.

bundle or bundle install is a Bundler command used to read the Gemfile and install dependencies to the machine in which it is ran on. bundler install --binstubs, specifically the --binstubs flag tells bundler to install the dependencies locally within the application directory. By default, this location is app_root/bin.

Within the application root directory, type the following into the Terminal: ls bin

You will see the executable dependencies such as:

  • rspec
  • rake
  • rails

and a bunch more.

During Rails development, you'll typically use rake quite often and you'll want to use the specific version your Gemfile has set. To do so, (if you did NOT use the --binstubs flag for installing dependencies) you'd prefix the rake command with bundle exec so the full command would be bundle exec rake db:create (to create the database as an example). The bundle exec would have to be used for any executable dependency. Typing that command over and over gets old, fast. This is why we use --binstubs and add to the Shells Path, "./bin" (export PATH:./bin:$PATH). It allows us to remove the bundle exec prefix and just do rake db:create.

Most likely you don't need to know much more than that, but if you want to know more, you can read the full documentation for Bundler.

With Rbenv setup, let's install a Ruby version:

in the terminal

rbenv install 2.0.0-p195
rbenv rehash
rbenv global 2.0.0-p195

This installs Ruby version 2.0.0-p195 (p195 is Patch #195). The rbenv rehash will reload rbenv. rbenv global 2.0.0-p195 will make Ruby version 2.0.0-p195 your default Ruby version to use, all the time. You can double check to make sure this worked correctly by doing:

ruby -v

and it should output: ruby 2.0.0-p195 If not, then an error occurred during one of the commands above when installing the new ruby version with rbenv. Check the terminal for any output to indicate the error. You can also run rbenv versions to see what ruby versions have been install with rbenv. If 2.0.0-p195 is missing from the list, then it was not installed. If it is in the list, and ruby -v is showing system ruby 1.8.7, then the rbenv global 2.0.0-p195 didn't take affect. You could try reloading your shell by restarting it and then running the rbenv global 2.0.0-p195 command again.

A few Gems to get started

You'll need a couple of Gems installed to get you setup for the Application Setup. Here's the list of commands and Gems to install:

gem install bundler rails foreman thin pg pry sinatra hub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment