setting up a MacBook Air 2011

This was copied from this great post by Frederico Araujo, with some small modifications for my own use case.

MacPorts is still a smart way to go, I tried Homebrew first and ended up in Ruby gem hell.

Also, read all the way to the bottom before you start (you may need to add wget via MacPorts before step 3).

Requirements:

  • Snow Leopard 10.6.4 or greater
  • Xcode 3.2.3, 2.4.1 or greater
  • Admin privileges on your mac.

Software preliminary:

  • Mysql 5.1.49 (macports)
  • Ruby 1.8.7 (macports)
  • Rubygems (download)

1. Preparing System

If you are upgrading from Leopard to Snow Leopard, I recommend you delete your old installation.

sudo rm -rf \
    /opt/local \
    /Applications/DarwinPorts \
    /Applications/MacPorts \
    /Library/LaunchDaemons/org.macports.* \
    /Library/Receipts/DarwinPorts*.pkg \
    /Library/Receipts/MacPorts*.pkg \
    /Library/StartupItems/DarwinPortsStartup \
    /Library/Tcl/darwinports1.0 \
    /Library/Tcl/macports1.0 \
    ~/.macports

Note: I was setting up a new MacBook Air, so I didn’t need to do this, but I left it here for reference.

1.1 Prepare PATH environment:

$vim ~/.bash_profile

Edit your ~/.bash_profile file and add these 2 lines.

Check if they are not there already.

export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH

1.2 Download and Install Xcode

http://developer.apple.com/technologies/xcode.html

Here I used the XCode install from my Snow Leopard disc, the above link is from the original post. The link includes the XCode SDK, I think, so it’s a bigger download (4gb) whereas the Snow Leopard XCode install is only 2.7gb which is all you need for just Rails stuff and with a smallish hard drive, every gb counts. Also, I did the install via driveshare from my other MacBook Pro.

1.3 Download Macports and install

Download Page: http://www.macports.org/install.php

Download Direct Link: http://distfiles.macports.org/MacPorts/MacPorts-1.9.2-10.6-SnowLeopard.dmg

You might use this guide for installing Macports:

Full Install Guide: http://guide.macports.org/#installing

1.3.1 Update macports

sudo port -v selfupdate

2. Mysql

2.1 Install Mysql

sudo port -v install mysql5-server mysql5

2.2 Make mysql autoload on startup

sudo port load mysql5-server
sudo -u mysql mysql_install_db5

3. Ruby, Rubygems, Rails, other gems

3.1 Install Ruby from macports

sudo port -v install ruby
$ ruby -v
ruby 1.8.7 (2010-08-08 patchlevel 302) [x86_64-darwin10]

3.2 download rubygems from http://rubygems.org/pages/download

cd /tmp
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
tar xpf rubygems-1.3.7.tgz
cd rubygems-1.3.7
sudo ruby setup.rb

3.3 Install rails, rake, rspec etc.

You may want a lot of other gems, I added xml-simple, fastercsv, calendar_helper, etc., so add gems as needed, especially the mysql gem which you will need – but do that as specified in the next step.

sudo gem install rake rails ruby-debug

3.4 install mysql gem

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- \
--with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config

DO THIS BEFORE step 3:

I had to run

sudo port install wget

before I was able to get the RubyGems install package (wget does not ship with Snow Leopard).

Other things I had to do:

I had to install git from a package here.

good luck!