RSS Log in
 

This is step 1 of Installing Ruby on a Mac and covers Xcode, Homebrew and Git.

 

Getting Started

_Step 1 - Xcode, Homebrew and Git_

Step 2 - Wget and OH MY ZSHELL

Step 3 - RVM

Step 4 - Ruby

Step 5 - Gems and Pow

Step 6 – Databases and Rails

Hello World

 

Xcode

Xcode is Apple’s IDE for developing applications for Mac OS X and iOS. It is freely available on the Mac App Store for Lion users and at the time of writing the latest major version was 4.2.1. This is an absolute pre-requisite to get started.

 

Go to the App Store, type in xcode in the search and simply click on the Install button.

Once the “install” is completed, go to Launchpad and click on Install Xcode to finalize the installation.

 

Next time you’ll re-open Launchpad, you will get a new Developer folder:

Developer Tools

 

To check everything is working, click on the Xcode icon. In the Xcode menu, go to File > New > Project or use Shift + CMD + N.

It should open the new project dialog:

Xcode IDE

 

Note that you can confirm the Xcode version installed on your system either by opening the About box or just by typing the following command in Terminal:

$ xcodebuild –version

The output on my system is:

Xcode 4.2
Build version 4D199

 

Side Note

Terminal is OS X terminal emulator. It is a Unix shell that allows you to interact with your system through a command-line interface.

To access it either open Spotlight (CMD + space), type in terminal and select rubyinstall4_thumb[3] or go to Launchpad, open the Utilities folder and click on the Terminal icon:

Terminal

 

Homebrew

Homebrew is a package manager that automates the process of downloading, installing and upgrading Unix software packages for OS X. It can also help with removing packages, versioning and managing software dependencies to ensure that everything runs properly. For a good description of what it does, check out this post by Andre Arko and the project Wiki. Homebrew has a dependency on the Developer Tools hence the need to install Xcode first. However once this is done, getting Homebrew on your machine is very straight forward.

 

Open a Terminal session and run this command:

$ ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"

 

The above runs cURL (Client for URLs) inside Ruby. cURL is a command-line tool that allows you to connect to a URL for transferring data. It is used to get or send files using a variety of protocols (e.g. FTP, HTTP, POP3 and many others).

 

If you go to the URL passed in as the argument, you’ll find a Ruby script that will download Homebrew and install it.

 

Here’s the meaning of the cURL options used above:

-f Fail silently (no output at all) on HTTP errors (H)
-s Silent mode
-S Show errors when they occur
-L Follow Location

To get a full list of command-line options, just type curl --help in a Terminal session.

 

Verify that Homebrew is now installed:

$ brew --version

This returned 0.8 on my machine.

 

Git

Before we can proceed with installing RVM (cf. step 3), we need to install Git (and git-core in particular). Git is a free distributed version control system originally developed by Linus Torvalds for Linux but is now available for Windows with msysgit and Mac OS X through the git-osx-installer. Git is also useful for downloading packages from the GitHub repository.

 

Actually Xcode has already installed a version of Git for us:

$ git --version

Output:

git version 1.7.5.4

It can be found in the /usr/bin/ folder (usr is a system folder and hidden by default in the Finder).

 

Side Note

On OS X, files starting with a . (dot) are hidden files. To make them visible in your Finder, run the following AppleScript:

tell application "Finder" to quit
do shell script "defaults write com.apple.finder AppleShowAllFiles YES"
delay 2
tell application "Finder" to run

You can check-out my previous post on running an AppleScript on OS X.

Alternatively simply run the command in your terminal session and quit/start any Finder windows:

defaults write com.apple.finder AppleShowAllFiles YES

To revert back to the OS X default, re-run the same command but replace YES by NO to hide the files again.

 

However we want to manage Git via Homebrew as it will give us more control over which version of Git we use. Installing Git with Homebrew is a breeze:

$ brew install git

The Git version installed by Homebrew will be found under /usr/local/Cellar/git/1.7.7.3 (or whatever is the latest version) so we expect this version to be used from now on. Right? Wrong.

If you run a git --version command you will still get the same version as before (1.7.5.4 in my case) and not 1.7.7.3 as expected. But how do we tell OS X to use this version of git and not the one installed by Xcode?

 

The safest way to do this is to amend the .bash_profile file - a configuration file that specifies environment settings used by the Bash shell (i.e. Terminal).

 

Open a session and tell the shell to load settings from the /usr/local/bin folder first:

$ echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile

If no .bash_profile file exists it will be automatically created for you with the text in quotes appended to it.

 

Reload the file (no need to leave your current Terminal session):

$ source ~/.bash_profile

 

That’s it! This should do the trick but just double check that the version used is the right one:

$ git --version

Output:

git version 1.7.7.3

 

You can now move on to the next step

 

If you see any inaccuracies, things that should be added, removed or corrected, please either leave a comment or drop me an email. Thanks.


Comments are closed
© Copyright 2013 TheBooleanFrog Powered by: BlogEngine.NET|Credits|Subscribe via RSS

Follow

twitter linkedin linkedin rss

TheBooleanFrog

Programming sticky notes and other distractions...