Sandbox
Much of what I’ve done is based on the work of Dan Benjamin at Hivelogic. Whether you compile manually (as Dan suggests) or use MacPorts, the goal is the same—to create a sandbox for your Ruby on Rails environment.
These instructions are meant to be quick and to the point. I won’t be going into great detail as to why I’ve done what I’ve done. There are many articles that explain why much better.
XCode
Be sure to install XCode tools from the Leopard installation DVD.
MacPorts
Download the latest version of MacPorts and install.
Path
Update .profile:
mate ~/.profile
Add these lines:
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
export MANPATH="/opt/local/share/man:$MANPATH"
Log out of the terminal session and begin a new one so the changes take hold.
Ports
I just install the necessary ports in one command.
sudo port install mysql5 +server git-core freeimage ruby rb-rubygems rb-termios rb-mysql
MySQL
Initialize MySQL database:
sudo mysql_install_db5 --user=mysql
Install MySQL 5 startup:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
For convenience, create a mysql link to mysql5 binary:
cd /opt/local/bin
sudo ln -s ../lib/mysql5/bin/mysql mysql
Secure MySQL
sudo mysql_secure_installation5
- Hit enter for current root password (because one hasn’t been set, yet)
- When it asks if you want a root password, it’s up to you. A development machine probably doesn’t need one.
- Yes, you do want to remove anonymous users
- Yes, you want to disallow root login remotely
- Yes, remove test database
- Yes, reload privilege tables now
GEMs
As of this writing, rubygems is at version 1.2.0. MacPorts installs the latest version. However, if a newer version becomes available, it’s easy to upgrade.
sudo gem list -r
sudo gem update --system
There are a fair number of GEMs to install. To install all the GEMs at once—put this in as one long line:
sudo gem install rake rails capistrano mongrel redgreen pdf-writer ZenTest ruby-debug haml rcov image_science rr
Then install the latest RedCloth
sudo gem install RedCloth -s http://code.whytheluckystiff.net
And the latest will_paginate
sudo gem install mislav-will_paginate -s http://gems.github.com
Shoulda
I’ve tried rspec, test-spec-on-rails, and finally Shoulda. Shoulda is the best. I highly recommend it. Shoulda is a plugin. To install it, change to the rails application directory and run this:
svn export https://svn.thoughtbot.com/plugins/shoulda/tags/rel-4.0.2 vendor/plugins/shoulda
Check out Shoulda’s documentation.
SSH Warning
Git is taking over source control management. After using it for several months, I understand why. It’s a huge jump in managing code and worth learning. However, installing git-core caused an unexpected problem.
Git-core depends on SSH, so MacPorts dutifully installs the SSH port. Because we changed our execution path to use /opt/local/bin before /usr/bin we will be using MacPorts version of ssh before we use Leopard’s version. This isn’t a problem except when you want to add your ssh key to the Leopard ssh agent.
Leopard loads a copy of ssh agent and can manage your ssh-keys on the secure Leopard keychain. This happens the first time a particular ssh-key is used to authenticate a connection. BUT only if you use Leopard’s version of ssh to make that connection.
What happened to me was that I had to create a new ssh-key. I did, loaded it on the servers, and tried connecting. But Leopard never asked to save the passphrase to the new key. To get around this I used the absolute path to Leopard’s ssh (/usr/bin/ssh) when making the connection. A Leopard dialog box appeared and asked for my key and then asked to save the passphrase in my login keychain.
After that, the MacPorts ssh binary works with Leopard’s ssh-agent. So it’s only a nuisance when you change or add keys.
Changelog
- Friday, 4 April 2008 – Added ‘rr’ to gem install list.
- Monday, 14 April 2008 – Updated git-core install.
- Friday, 4 July 2008 – Added improved RedCloth and will_paginate gems. Converted port install to only one line. Added Shoulda plugin. Added SSH warning.