Written on August 21, 2012 at 12:01 pm

Note: After going through some form of these steps three times already on other machines, I decided to document these steps as I installed Ruby, Rails, mysql, etc on my shiny MacBook Air 13″. Hopefully it helps someone else.

Thanks to Brickghost for his step-by-step notes from his last install that got me most of the way to this.

Pre-requisites: Most of the commands in here take place in the command line (terminal). That and XCode developer tools are the basic things you’ll need.

You’ll need XCode 4.4 (current version as of the date I write this) as a registered Mac developer, I downloaded this from here, I believe it’s also available from the Mac App Store. Go ahead and download that, I’ll see you in an hour or two. I think you can get by only downloading the command line tools, but I couldn’t get them to work, so I can’t verify that.

(Optional) You’ll probably want to show hidden files on your Mac. To do this in Mountain Lion, type this in terminal:

defaults write com.apple.finder AppleShowAllFiles TRUE killall -HUP Finder 

1. Install homebrew

I think homebrew is the easiest way to go with some of the dependencies. Your opinion may be different, but this is my guide, so away we go…. To install homebrew, copy and paste the following in terminal.

ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go) 

If it’s successful, you should see this message (with your machine name and path instead of mine):

==> Installation successful! You should run `brew doctor' *before* you install anything. Now type: brew help Brians-MacBook-Air:~ creativereason$ brew doctor Your system is raring to brew. 

2. Install Git.

So, now that that is up, let’s go ahead and install git (via homebrew).

Type the following in terminal:

brew install git 

If you are successful, you will see something like this:

==> Downloading http://git-core.googlecode.com/files/git-1.7.12.tar.gz ######################################################################## 100.0% ==> make prefix=/usr/local/Cellar/git/1.7.12 CC=/usr/bin/clang CFLAGS=-Os -w -pipe -march=native -Qunused-arguments -mmacosx-version-min=10.8 LDFLAGS=-L/usr/local/lib install ==> make CC=/usr/bin/clang CFLAGS=-Os -w -pipe -march=native -Qunused-arguments -mmacosx-version-min=10.8 LDFLAGS=-L/usr/local/lib ==> make clean ==> Downloading http://git-core.googlecode.com/files/git-manpages-1.7.12.tar.gz ######################################################################## 100.0% ==> Downloading http://git-core.googlecode.com/files/git-htmldocs-1.7.12.tar.gz ######################################################################## 100.0% ==> Caveats The OS X keychain credential helper has been installed to: /usr/local/bin/git-credential-osxkeychain The 'contrib' directory has been installed to: /usr/local/share/git-core/contrib ==> Caveats Bash completion has been installed to: /usr/local/etc/bash_completion.d ==> Summary /usr/local/Cellar/git/1.7.12: 1235 files, 24M, built in 34 seconds 

3. Next, let’s install RVM (Ruby Version Manager)

RVM is a great tool that manages your ruby versions and gems. To install it, paste the following into terminal:

bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) 

Note: After you install RVM, you’ll need to restart your terminal (not just close and re-open)

Test to make sure RVM installed successfully, to do so, try this (in terminal):

type rvm | head -1 

If successful, you should see:

rvm is a function 

4. Install Ruby.

To show all available Ruby versions, enter this in terminal:

rvm list known 

I picked this one:

rvm install 1.9.3 

If like me, you are on a clean build and never previously installed a GCC installer, you will get a long winded message, but the gist is we need a GCC compiler, but it’s going to try to compile anyway, mine did.

So, when I finished letting ruby install after that message, I got this:

Ruby 'ruby-1.9.3-p194' was built using clang - but it's not (fully) supported, expect errors. 

I restarted terminal to make sure I was using the latest.

Ran brew doctor to make sure everything I setup prior was kosher. I got a warning about my path’s being out of order (affecting git and others), but efforts to fix it broke RVM. So I ended up needing to edit my bash profile.

5. Get running on rails.

To install rails, is very easy. Just run this in terminal:

gem install rails 

6. Setup Github SSH keys and info (Optional)

  • Follow this guide for setting up your github user name and info.
  • Follow this guide for setting up your SSH keys and keygen.

7. Setup mysql (Optional for some devs, not for me)

I used homebrew to install mysql.

brew install mysql 

Once installed, you’ll see a message about not having to run as sudo, run this, mine was this:

unset TMPDIR mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp 

Also, you’ll want to make a root password if you ever have real data in your dev dbs on your machine. You get the messages about this when you do run the above install_db message.

mysql.server start #needs to be running to change passwords /usr/local/Cellar/mysql/5.5.25a/bin/mysqladmin -u root password 'new-password' 

If you want to install apache / PHP (optional for pure ruby / rails devs since webbrick does this locally, but I’m sure I’ll need it again some day, follow this guide

Happy coding!

9 Comments

Category Code, Web/Tech | Tags: , , , , , ,

Related Posts (automatically added):

Social Networks : Technorati, Stumble it!, Digg, de.licio.us, Google, Twitter, Yahoo, reddit, Blogmarks, Ma.gnolia.

You can follow any responses to this entry through the RSS 2.0 feed.

9 Comments so far
  1. maggie kean says:

    thank you! this saved me a lot of time …
    i ran into a little problem with rails hanging when i did ‘gem install rails’ … i noticed that my current version of ruby was 1.8.7 … when i made 1.9.3 the default, it worked …

  2. ZeRobLaCk says:

    Hey Dude!

    Great guide.. but i have and error and i think on mountain lion with the last Xcode is a bug, i get this error :

    $Fetching: json-1.7.5.gem (100%)
    Building native extensions. This could take a while…
    ERROR: Error installing rails:
    ERROR: Failed to build gem native extension.

    /Users/user/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
    creating Makefile

    make
    compiling generator.c
    make: /usr/bin/gcc-4.2: No such file or directory
    make: *** [generator.o] Error 1

    So aplicated a symbolic link of my gcc and fix it :
    $ sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2

    I put this if other have the same problem.

    Best!!!

  3. karthickayyapillai says:

    amazingly simple and organised thanks very much for saving frustration

  4. Rich4321 says:

    Overall this is a good guide. But I did run into some glitches.
    When I entered type rvm | head -1
    I got dvm not found. To fix this enter:
    source ~/.rvm/scripts/rvm
    Then another at rvm install 1.9.3
    I got another error about make file. If this happens to you,
    enter rvm requirements then you will see serval commands. Use the long one: brew install autoconf automake apple-gcc42 libtool pkg-config openssl readline libyaml sqlite libxml2 libxslt libksba rails -version after it’s done then run rvm install 1.9.3

  5. Chad Evans says:

    Coming from a fresh 10.8 install, I had a number of errors following these steps. Persistence and lots of Google searches later, I found the culprit. Lack of required libraries. Here are the commands I found on StackOverflow that saved the day:

    $ rvm remove 2.0.0 # get rid of unsuccessful installation
    $ rvm get head --autolibs=3 # get the latest RVM and build required libs
    $ rvm requirements # just in case, install all other required stuff
    $ rvm install ruby-2.0.0

    When I typed in $ rvm requirementsto the terminal, a series of copy-paste brew install commands came up. After going through these automated installations, I removed all versions of Ruby I had been messing with and everything installed perfectly, no errors.

    Lesson learned – $ rvm requirements is an essential step!

  6. [...] the tutorials i found mention installing mysql.Unable to install mysql2 gem OS X Mountain Lionwww.creativereason.com/how-to-…madebyhoundstooth.com/blog/ins…blog.teamtreehouse.com/install…Read more ch_client = [...]

  7. Frederico says:

    I tried to Install homebrew, but this error appeared

    sh-3.2# ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
    sh: syntax error near unexpected token `('

  8. google adwords login…

    Blog | Creative Reason…

9 Responses to “How to do a clean install of Ruby on Rails on OS X Mountain Lion (10.8)”




XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Inappropriate comments will be removed at admin's discretion.