Mac OSX

Xcode Command Line Tools

Xcode is an integrated development environment (IDE) with a suite of tools for developing software for OS X and iOS. But Xcode is more than what just meets the eye. Ruby gems often use so called "native extensions", that connects them with other non-Ruby components on your machine. Without Xcode installed, you don't have the necessary code compilers installed and can not use those extensions. While installing Xcode you also install LLVM, GCC, and many other developer tools.

For the purpose of this course, we are going to install Xcode Command Line Tools, a part of the Xcode IDE, without installing the entire Xcode package.

Check if Xcode Command Line Tools are installed:

$ xcode-select -p

Install:

$ xcode-select --install

Work your way through the dialogs presented by the installer, complete the process and verify installation:

$ xcode-select -p
/Library/Developer/CommandLineTools
# or: 
/Applications/Xcode.app/Contents/Developer

Also, verify that LLVM-GCC is installed:

$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.1.76)
Target: x86_64-apple-darwin14.5.0
Thread model: posix

Homebrew

Homebrew is “the missing package manager for OSX” written in Ruby. It allows you to easily install hundreds of open-source tools. Homebrew complements OSX. Install your gems with gem install, and their dependencies with brew install.

In your terminal, run the following command:

$ 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 the response Your system is ready to brew, you're all set.

RVM

Ruby Environment Manager (RVM) is a tool that allows you to install, manage and work with multiple ruby environments. RVM lets you deploy each project with its own completely self-contained and dedicated environment, from the specific version of ruby, all the way down to the precise set of required gems to run your application.

To install RVM, run the following command in your terminal:

$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
$ curl -L https://get.rvm.io | bash -s stable --auto-dotfiles --autolibs=enable --ruby

Once the installation is complete you must load RVM to make RVM available in your current session. Otherwise you'll need to restart your terminal. Run the following command in terminal:

$ source ~/.rvm/scripts/rvm

Verify your install:

$ type rvm | head -1
rvm is a function

If you get the response rvm is a function it means you're all good.

Now you can check what ruby version/versions you have installed on your machine with the list command:

$ rvm list

And install new rubies with:

$ rvm install 2.2.0  #or whatever version you need

Switching between versions is done with the use command:

$ rvm use 2.2.0

Read the RVM documentation to see all the different actions you can use.

Bundler

Bundler is a program for managing gem dependencies in your Ruby projects. With Bundler you can specify which gems your program needs, what versions they should be at, it can help you install them, load them at runtime and distribute them with your software.

"Bundler provides a consistent environment for Ruby projects by tracking and installing the exact gems and versions that are needed." - http://bundler.io/

You install it with a terminal command:

$ gem install bundler

Now, you can keep control of which gems you programs are using by adding them to a file called Gemfile in your project folder (Please note the capital 'G').

An example Gemfile can look like this:

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

To install those gems and their dependencies, you run the following command in your terminal:

$ bundle install

We'll be covering bundler and gems more extensively later on when we work with our challenges.

Git

Git is a version control system that we'll be using extensively during the course. Version Control lets you track your files, changes and avoid general chaos over time.

With Homebrew, installing Git is easy:

$ brew install git

And verify your installation:

$ git --version
git version 2.4.4

Atom

There are many editors out there you can use. Sublime is one, TextMate is another, but our editor of choice for this workshop is Atom. It is brought to us by the good people of GitHub and comes with over 3000 extension packages - all open sourced.

"Atom is a text editor that's modern, approachable, yet hackable to the core—a tool you can customize to do anything but also use productively without ever touching a config file." - https://atom.io

Download and install Atom by following the instructions on their web site. Once you are done you can browse around for some packages you might find useful. Or you wait with that until you actually know what 'useful' is in the context of coding. If you want to find out more about how to install Atom packages head over to the excellent documentation site.

For now, what you really want to do is to set Atom as the default editor fir Git (trust me, you'll going to need it):

$ git config --global core.editor "atom --wait"

Terminal prompt

When you work with git and version control it is a good idea to set up your prompt that displays some useful information such as:

  • What branch are you currently on

  • What is your current status in regard to your GitHub repository (origin)

There is a very nice modification made availiable on GitHub called Bash Git Prompt. You an install it using Homebrew with these steps:

$ brew install bash-git-prompt

Once the installation is complete, you need to open the .bash_profile file and add the following configuration:

# ~/.bash_profile

if [ -f "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh" ]; then
    source "$(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh"
fi

Once you save and close .bash_profile, go back to your terminal and reload it:

source ~/.bash_profile

Your terminal prompt will now show a lot more useful information that will help you in your coding.

That's it!

You are all set up, you have your necessary compilers (with Xcode CLT) to be able to effectively use ruby gems, your package managers (RVM, Bundler and Homebrew) are in place, you have your Ruby versions installed, a version control system (Git) and you have a text editor. In your terminal, where you will be spending most of your time, you have a prompt that tells you all you need to know about where you are in your version control process. You are all good!

Last updated