Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwccoin/5e2c30a0bb60c9fe11d2cf070f52efce to your computer and use it in GitHub Desktop.
Save kwccoin/5e2c30a0bb60c9fe11d2cf070f52efce to your computer and use it in GitHub Desktop.
How to Install Xcode, Homebrew, Git, RVM, Ruby, Rails, Heroku Toolbelt and Postgres (Yosemite)

###Step 1: Install XCode

Check if the full Xcode package is already installed:

$ xcode-select -p

If you see:

/Applications/Xcode.app/Contents/Developer

the full Xcode package is already installed. Otherwise:

xcode-select --install

You should see the pop up below on your screen. Click Install when it appears.

Once the software is installed, click Done.

Before you go to the next step, verify that you’ve successfully installed Xcode Command Line Tools:

$ xcode-select -p

You should see:

/Library/Developer/CommandLineTools

Just to be certain, verify that gcc is installed:

$ gcc --version

If all went well, you should see the GCC version in the output.

It will show something like this:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn) 
Target: x86_64-apple-darwin14.0.0
Thread model: posix

###Step 2: Install Homebrew

Run the command, and follow the instructions when prompted.

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

Once the installation is successful, run the following command:

$ brew doctor

If you get Your system is ready to brew, you can move on to the next step.

###Step 3: Configure Git

Verify that Git is installed:

$ which git

You should get /usr/local/bin/git.

To check git version:

git version

You should get git version 1.9.3 (Apple Git-50).

If everything is working, configure Git with your name and email.

First, list the current settings with the git config -l --global command.

You should get fatal: unable to read config file '/Users/.../.gitconfig': No such file or directory.

Proceed with these commands:

$ git config --global user.name "Your Full Name”
$ git config --global user.email "Your Email Address”

Run the git config -l --global again.

###Step 4: RVM

The RVM website explains how to install RVM. Here’s the simplest way:

$ \curl -L https://get.rvm.io | bash -s stable --ruby

If you already have RVM installed, update it to the latest version and install Ruby:

$ rvm get stable --autolibs=enable
$ rvm install ruby $ rvm --default use ruby-2.1.4

This will take a few minutes, and once it’s done, quit and relaunch Terminal, then run this command:

$ type rvm | head -1

If you get rvm is a function, that means RVM was successfully installed.

To make sure the latest versions of RVM, Ruby and Rails were installed, run the commands below:

For RVM

$ rvm -v

You should get rvm 1.26.00 or higher.

For Ruby

$ ruby -v

You should get ruby 2.1.4 or higher.

To make sure your system is still ready to brew:

$ brew doctor

If everything went well, you’re done! Your machine is now set up with the basic tools for web development.

####Check the Gem manager

RubyGems is the gem manager in Ruby.

Check the installed gem manager version.

$ gem -v
2.4.2

Use gem update --system to upgrade the Ruby gem manager.

$ gem update --system

###Step 5: RVM Gemsets (Optional)

Not all Rails developers use RVM to manage gems, but many recommend it.

Display a list of gemsets:

$ rvm gemset list
$ gemsets for ruby-2.1.4 => (default) global

Only the “default” and “global” gemsets are pre-installed.

If you get an error rvm is not a function, close your console and open it again.

####RVM’s Global Gemset

See what gems are installed in the “global” gemset:

$ rvm gemset use global
$ gem list

A trouble-free development environment requires the newest versions of the default gems.

####Faster Gem Installation

By default, when you install gems, documentation files will be installed. Developers seldom use gem documentation files (they’ll browse the web instead).

Installing gem documentation files takes time, so many developers like to toggle the default so no documentation is installed.

Here’s how to speed up gem installation by disabling the documentation step:

$ echo "gem: --no-document" >> ~/.gemrc

This adds the line gem: --no-document to the hidden .gemrc file in your home directory.

####Nokogiri

Nokogiri is a gem that is a dependency for many other gems. Nokogiri is a gem that requires compilation for your specific operating system.

As such, if your system environment doesn’t match Nokogiri’s requirements, compilation of Nokogiri will fail. If your system is configured properly, you’ll be able to compile Nokogiri.

However, compilation takes time. Every time you install the Nokogiri gem, you’ll wait (as long as five minutes).

To save time, install the Nokogiri gem in the RVM global gemset:

$ gem install nokogiri

###Step 6: Rails

Check for the current version of Rails. Rails 4.1.7 was current when this was written.

You can install Rails directly into the global gemset. However, many developers prefer to keep the global gemset sparse and install Rails into project-specific gemsets, so each project has the appropriate version of Rails.

If you install Rails at this point, you will install it into the global gemset.

Instead, make a gemset just for the current stable release:

$ rvm use ruby-2.1.4@rails4.1 --create

Here are the options you have for installing Rails.

If you want the most recent stable release:

$ gem install rails 
$ rails -v

Or you can get a specific version.

For example, if you want the Rails 3.2.18 release:

$ gem install rails --version=3.2.18 $ 
$ rails -v

###Step 7: Heroku Toolbelt

Assuming that you have an account (sign up if you don't), let's install the Heroku Client for the command-line. Heroku offers a Mac OS X installer, the Heroku Toolbelt, that includes the client. But for these kind of tools, I prefer using Homebrew. It allows us to keep better track of what we have installed.

Luckily for us, Homebrew includes a heroku-toolbelt formula:

$ brew install heroku-toolbelt

The formula might not have the latest version of the Heroku Client, which is updated pretty often. Let's update it now:

$ heroku update

Login to your Heroku account using your email and password:

$ heroku login

If this is a new account, and since you don't already have a public SSH key in your ~/.ssh directory, it will offer to create one for you. Say yes! It will also upload the key to your Heroku account, which will allow you to deploy apps from this computer.

If it didn't offer create the SSH key for you (i.e. your Heroku account already has SSH keys associated with it), you can do so manually by running:

$ mkdir ~/.ssh
$ ssh-keygen -t rsa

Keep the default file name and skip the passphrase by just hitting Enter both times. Then, add the key to your Heroku account:

$ heroku keys:add

Heroic has a great article about Managing Your SSH Keys.

Once the key business is done, you're ready to deploy apps! Heroku has a great Getting Started guide, so you can just refer to that, although the one linked here is for Rails.

###Step 8: PostgreSQL

Installing PostgreSQL is easy with Homebrew.

Before you install anything with Homebrew, you should always make sure it’s up to date and that it’s healthy:

$ brew update
$ brew doctor

To install Postgres, type:

$ brew install postgresql

It might take a little while to compile and install. After compilation is done, it’ll give you some instructions to finish setting it up.

$ initdb /usr/local/var/postgres

Now run the following commands to start Postgres at login, so we already have Postgres running on the background:

mkdir -p ~/Library/LaunchAgents
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

To see whether we have access to the server, psql in the terminal and create a database:

$ psql

If you should see an error message like pqsl: FATAL: database "yourusername" does not exist, after running the above command, you’ll have do this:

$ createdb yourusername

where yourusername is the actual username on your Mac.

Enter psql again to accesss the database.

###Step 9: MySQL (optional)

Because I use MySQL for work, to install:

$ brew doctor
$ brew install mysql

Set autostart

$ ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

Or, if you don't want/need launchctl, you can just run:

$ mysql.server start
$ mysql

That’s it. :)

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