Migrating to Snow Leopard for Rails Development - A Definitive Guide
I spent a good chunk of the last couple of days upgrading one of my Macs to Snow Leopard (OS X 10.6), and keeping notes as I went. I had several goals here:
I'm pretty happy with where it all ended up, but please realize that this guide is only definitive for me: just because this is the way it worked for me does not mean it's the only way to set things up for Rails development. I hope some folks find this helpful, but the main reason I wanted to work all this out was to handle our own in-house Macs.
1. Install external hard drive. I used a LaCie d2 Quadra. At $150 with free shipping (we happily pay for Amazon Prime) it's cheap insurance. Didn’t bother with their Setup Assistant (who the heck still writes software that requires Rosetta?), just erased it with Disk Utility and formatted it as one big journaled OS X volume.
2. Install SuperDuper (http://www.shirt-pocket.com/SuperDuper/SuperDuperDescription.html). I’m sure Carbon Copy Cloner is just as good, I just happen to be a SuperDuper user. Even if you're not a paying customer, SuperDuper is free to use in interactive mode, which is all this procedure requires.
3. Log out and log back in with the shift key held down to prevent startup items from running.
4. Launch SuperDuper and back up the internal hard drive to the external hard drive with the "Backup - All Files" script.
5. Restart, holding down the Option key when the box restarts. This will let you choose to restart from the backup you just made. Booting from the external drive will take a lot longer than from the internal one, but don't skip this step. You'll feel pretty darned stupid if you bootable backup isn't. Hold down shift after selecting the drive to bypass startup items so you don't clutter the backup.
6. While you're in there, launch terminal and :
I didn't use the port list for anything myself, but it was a good reference for things I needed to install otherwise.
7. Now it's time to do some cleaning up of your backup to prepare for the later migration. Mac's Migration Assistant doesn't offer a lot of granularity, so you need to get rid of anything from your Applications, Documents, and other descendants of your home directory that you don't want to move. The more you delete now, the faster the migration will go, so delete any applications and documents that you don't want on the rebuilt Mac. Good time to clean up the Dock as well. I blew away my local gems as well at this point.
I also recommend completely blowing away /usr/local and /opt/local to make sure you’re doing a “clean everything” install even after migrating. Edit your .bash_login to remove them from the path as well (optionally, you may want to rename these directories to have them available for reference).
8. If you're a PostgreSQL user, make a backup of your databases. Tyler Hunt has clear instructions for this.
9. Put in the Snow Leopard DVD. Ignore the Finder window when it pops up.
10. Power down the computer.
11. Unplug the backup drive. No sense taking chances.
12. Restart with the option key held down again. Choose the Mac OS X Install DVD to boot from.
13. The "Erase and Install" option is gone from the Snow Leopard installer, so when you get to the "Install Mac OS X" screen select Disk Utility from the Utilities menu instead.
14. Select the "Macintosh HD" partition on your hard drive. Select the Erase tab. Select the "Mac OS Extended (Journaled)" format. Click Erase. Grit your teeth and confirm.
15. When OS X is done reformatting the partition, close Disk Utility, click Continue on the OS X installer, and work your way through the rest of the prompts.
16. When you get to the "Do You Already Own a Mac?" screen (this is after the installation restart, so don't panic when the machine restarts), plug the external drive back in. Select "From another volume on this Mac" and click Continue.
17. The top of the "Transfer Your Information" screen should show that you're transferring from the external drive. Leave all the options checked and click Transfer.
18. Log into happy new OS X. Bask in it for a little bit. Wait a minute for Software Update to kick in, or run it manually and install whatever it comes up with. If it doesn't find anything, that's great.
19. While you've got the Snow Leopard DVD in the drive, pop option the Optional Installs folder and install XCode.
20. I personally prefer wget to curl (just habit, I suppose) which means that I have to install it:
GNU wget home page
[sourcecode language='bash']
Download wget-latest.tar.gz from http://ftp.gnu.org/gnu/wget/
tar -xzvf wget-latest.tar.gz
cd wget-1.11.4/
./configure
make
sudo make install
[/sourcecode]
21. I'm trying a no-MacPorts approach this time around. This means installing a current readline by hand, since multiple pieces of software still reportedly have issues with Apple's default version:
GNU Readline home page
[sourcecode language='bash']
wget ftp://ftp.cwru.edu/pub/bash/readline-6.0.tar.gz
tar -xvzf readline-6.0.tar.gz
cd readline-6.0
./configure
make
sudo make install
[/sourcecode]
22. This is a good point to make sure your .bash_login and .bash_profile are the way you want them. For me, that’s an empty .bash_login and a pretty minimal .bash_profile. Here’s my .bash_profile, though you probably want to tune your own:
23. Snow Leopard includes a recent version of SQLite, but you know, as long as we're building things we may as well make it current.
SQLite Download Page
SQLite Build Instructions
[sourcecode language='bash']
wget http://www.sqlite.org/sqlite-amalgamation-3.6.17.tar.gz
tar -xvzf sqlite-amalgamation-3.6.17.tar.gz
cd sqlite-3.6.17/
./configure
make
sudo make install[/sourcecode]
24. Now for MySQL. If you have a previous version of MySQL installed, you probably have the old MySQL preference pane, which doesn't work under Snow Leopard. Fortunately swoon.net has recompiled a 64-bit version. Grab it and install it. Then pop into System Preferences and stop your MySQL server if it's running.
25. Given that there are prebuilt x64 binaries for OS X, I don't feel any particular need to build MySQL from scratch. I've found anything past MySQL 5.1 to be problematic for Rails.
MySQL Download Page
Pick a mirror and download the "Mac OS X 10.5 (x86_64)" version. Mount the dmg and run the MySQL package and then the MySQL startup item package. Then start MySQL:
[sourcecode language='bash']
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
[/sourcecode]
26. If you have existing MySQL databases to bring over from an old version, see the instructions from edward - remember to change the old directory name to match the version you were running before.
27. SQLite and MySQL are nice, but these days I’m using PostgreSQL for new Rails work. If you want a shortcut, there’s an installer that runs on OS X: grab it and run it. But to get best performance, you probably should build by hand. There are good instructions from Tyler Hunt for that, though you need to update the download version. Don’t install the postgres gem though; it’s slow and outdated, and anyhow there’s still work to do to get gems set up.
PostgreSQL source code
[sourcecode language='bash']
wget ftp://ftp.postgresql.org/pub/source/v8.4.0/postgresql-8.4.0.tar.gz
tar -xvzf postgresql-8.4.0.tar.gz
cd postgresql-8.4.0
./configure --enable-thread-safety --with-bonjour
[/sourcecode]
And follow Tyler's instructions from there for installing, creating a group and user, and hooking up launchd.
28. Reload your old PostgreSQL databases.
29. Databases in hand, let’s turn to ruby. Given that I expect a transition to ruby 1.9 over the next year, and I find myself wanting to test on odd rubies from time to time, I’m going to completely ignore the system ruby except to bootstrap a multiruby setup. Fortunately, the recently-released Ruby Version Manager is working great already.
Ruby Version Manager homepage
[sourcecode language='bash']
sudo gem install rvm
rvm-install
rvm install 1.8.6 -C --enable-shared,--with-readline-dir=/usr/local
rvm install 1.8.7 -C --enable-shared,--with-readline-dir=/usr/local
rvm install 1.9.1 -C --enable-shared,--with-readline-dir=/usr/local
rvm install 1.9.2 -C --enable-shared,--with-readline-dir=/usr/local
rvm 1.8.7 --default
[/sourcecode]
I'm skipping REE, JRuby, and Rubinius for the moment, but will likely add them to the system later.
30. Time to install the two problematic gems. I’m just going to do this under 1.8.7 for now, but will update the other rubies later.
MySQL: (from Greg Benedict)
[sourcecode language='bash']
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
[/sourcecode]
PostgreSQL: (from iCoreTech)
[sourcecode language='ruby']
sudo -s
export ARCHFLAGS='-arch x86_64'
export PATH=/usr/local/pgsql/bin:${PATH}
gem install pg
exit
[/sourcecode]
31. The rest of the gems should be easier. Grab the gemlist.txt file you created way back at the start and edit it to one gem name per line. Ditch anything you know you don’t need. Then fire up IRB and run:
[sourcecode language='ruby']
File.open('/Users/mike/gemlist.txt').each_line {|line| `sudo gem install #{line.split.first}`}
[/sourcecode]
Obviously change the file name to match where you put it on your own drive.
This could use some tweaking to deliver feedback.
[stalled at RedCloth?]
32. This is a good time to get git on the system. Fortunately, there’s an easy and functional OS X installer for that. Download, mount the disk image, and run the installer and shell script.
33. imagemagick used to be a bear, but at the moment there’s a good install script for it on GitHub. So, now that you have your shiny new copy of git:
[sourcecode language='bash']
git clone git://github.com/maddox/magick-installer.git
cd magick-installer/
./magick-installer.sh
[/sourcecode]
34. I also need memcached locally. Wincent has good install instructions:
[sourcecode language='bash']
wget http://www.monkey.org/~provos/libevent-1.4.12-stable.tar.gz
tar xvzf libevent-1.4.12-stable.tar.gz
cd libevent-1.4.12-stable
./configure
make
sudo make install
wget http://memcached.googlecode.com/files/memcached-1.4.1.tar.gz
tar xvzf memcached-1.4.1.tar.gz
cd memcached-1.4.1
./configure
make
sudo make install
[/sourcecode]
35. I’d like to run gem server locally on a startup basis to handle my gem RDoc needs, but I need to figure out how (or whether) that can be made to play nicely with rvm. Meanwhile, bdoc is an acceptable alternative:
[sourcecode language='bash']
sudo gem install manalang-bdoc
[/sourcecode]
36. Finally (for now!) I prefer most as a pager to less or more. It supports paging forwards and backwards, split windows, and can even drop the file you're paging right into your editor of choice.
Most home page
You’ll need some prerequisites first:
pcre:
[sourcecode language='bash']
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz
tar xvzf pcre-7.9.tar.gz
cd pcre-7.9
./configure
make
sudo make install
[/sourcecode]
Oniguruma:
[sourcecode language='bash']
wget http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.1.tar.gz
tar xvzf onig-5.9.1.tar.gz
cd onig-5.9.1
./configure
make
sudo make install
[/sourcecode]
S-Lang:
[sourcecode language='bash']
wget ftp://space.mit.edu/pub/davis/slang/v2.2/slang-2.2.0.tar.gz
tar xvzf slang-2.2.0.tar.gz
cd slang-2.2.0
./configure
make
sudo make install
[/sourcecode]
And now most at last:
[sourcecode language='bash']
wget ftp://space.mit.edu/pub/davis/most/most-5.0.0.tar.gz
tar xvzf most-5.0.0.tar.gz
cd most-5.0.0
./configure
make
sudo make install
[/sourcecode]
And there you have it! Start to finish, this process took me about 3 hours on a MacBook Pro with around 90GB of data that I wanted to save. I expect it to take much longer on the desktop with the correspondingly larger hard drive, but much of that will be overnight backup and restore times. If you have any tweaks and suggestions, feel free to add them to the comments.
- Develop a repeatable process I could use on my main development box
- Set up multiple versions of Ruby, as I expect 1.9 compatibility to be increasingly important
- Avoid MacPorts, as it's been problematic for me and I don't like two copies of everything
- Prevent disasters
- Migrate applications and documents from the previous setup on the same box
I'm pretty happy with where it all ended up, but please realize that this guide is only definitive for me: just because this is the way it worked for me does not mean it's the only way to set things up for Rails development. I hope some folks find this helpful, but the main reason I wanted to work all this out was to handle our own in-house Macs.
1. Install external hard drive. I used a LaCie d2 Quadra. At $150 with free shipping (we happily pay for Amazon Prime) it's cheap insurance. Didn’t bother with their Setup Assistant (who the heck still writes software that requires Rosetta?), just erased it with Disk Utility and formatted it as one big journaled OS X volume.
2. Install SuperDuper (http://www.shirt-pocket.com/SuperDuper/SuperDuperDescription.html). I’m sure Carbon Copy Cloner is just as good, I just happen to be a SuperDuper user. Even if you're not a paying customer, SuperDuper is free to use in interactive mode, which is all this procedure requires.
3. Log out and log back in with the shift key held down to prevent startup items from running.
4. Launch SuperDuper and back up the internal hard drive to the external hard drive with the "Backup - All Files" script.
5. Restart, holding down the Option key when the box restarts. This will let you choose to restart from the backup you just made. Booting from the external drive will take a lot longer than from the internal one, but don't skip this step. You'll feel pretty darned stupid if you bootable backup isn't. Hold down shift after selecting the drive to bypass startup items so you don't clutter the backup.
6. While you're in there, launch terminal and :
gem list > gemlist.txt
port list installed > portlist.txt
I didn't use the port list for anything myself, but it was a good reference for things I needed to install otherwise.
7. Now it's time to do some cleaning up of your backup to prepare for the later migration. Mac's Migration Assistant doesn't offer a lot of granularity, so you need to get rid of anything from your Applications, Documents, and other descendants of your home directory that you don't want to move. The more you delete now, the faster the migration will go, so delete any applications and documents that you don't want on the rebuilt Mac. Good time to clean up the Dock as well. I blew away my local gems as well at this point.
I also recommend completely blowing away /usr/local and /opt/local to make sure you’re doing a “clean everything” install even after migrating. Edit your .bash_login to remove them from the path as well (optionally, you may want to rename these directories to have them available for reference).
8. If you're a PostgreSQL user, make a backup of your databases. Tyler Hunt has clear instructions for this.
9. Put in the Snow Leopard DVD. Ignore the Finder window when it pops up.
10. Power down the computer.
11. Unplug the backup drive. No sense taking chances.
12. Restart with the option key held down again. Choose the Mac OS X Install DVD to boot from.
13. The "Erase and Install" option is gone from the Snow Leopard installer, so when you get to the "Install Mac OS X" screen select Disk Utility from the Utilities menu instead.
14. Select the "Macintosh HD" partition on your hard drive. Select the Erase tab. Select the "Mac OS Extended (Journaled)" format. Click Erase. Grit your teeth and confirm.
15. When OS X is done reformatting the partition, close Disk Utility, click Continue on the OS X installer, and work your way through the rest of the prompts.
16. When you get to the "Do You Already Own a Mac?" screen (this is after the installation restart, so don't panic when the machine restarts), plug the external drive back in. Select "From another volume on this Mac" and click Continue.
17. The top of the "Transfer Your Information" screen should show that you're transferring from the external drive. Leave all the options checked and click Transfer.
18. Log into happy new OS X. Bask in it for a little bit. Wait a minute for Software Update to kick in, or run it manually and install whatever it comes up with. If it doesn't find anything, that's great.
19. While you've got the Snow Leopard DVD in the drive, pop option the Optional Installs folder and install XCode.
20. I personally prefer wget to curl (just habit, I suppose) which means that I have to install it:
GNU wget home page
[sourcecode language='bash']
Download wget-latest.tar.gz from http://ftp.gnu.org/gnu/wget/
tar -xzvf wget-latest.tar.gz
cd wget-1.11.4/
./configure
make
sudo make install
[/sourcecode]
21. I'm trying a no-MacPorts approach this time around. This means installing a current readline by hand, since multiple pieces of software still reportedly have issues with Apple's default version:
GNU Readline home page
[sourcecode language='bash']
wget ftp://ftp.cwru.edu/pub/bash/readline-6.0.tar.gz
tar -xvzf readline-6.0.tar.gz
cd readline-6.0
./configure
make
sudo make install
[/sourcecode]
22. This is a good point to make sure your .bash_login and .bash_profile are the way you want them. For me, that’s an empty .bash_login and a pretty minimal .bash_profile. Here’s my .bash_profile, though you probably want to tune your own:
export PATH=/usr/local/git/bin:/usr/local/bin/src:/usr/local/bin:
/usr/local/sbin:/usr/local/mysql/bin:~/bin:$PATH
export EDITOR='mate -w'
export PAGER=most
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) !=
"nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null |
sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1='\[33[1;36m\]\h\[33[0;33m\] \w \[33[31;40m\]
$(parse_git_branch)\[33[00m\] $ '
export HISTCONTROL=erasedups
export HISTSIZE=10000
shopt -s histappend
EVENT_NOKQUEUE=yes
23. Snow Leopard includes a recent version of SQLite, but you know, as long as we're building things we may as well make it current.
SQLite Download Page
SQLite Build Instructions
[sourcecode language='bash']
wget http://www.sqlite.org/sqlite-amalgamation-3.6.17.tar.gz
tar -xvzf sqlite-amalgamation-3.6.17.tar.gz
cd sqlite-3.6.17/
./configure
make
sudo make install[/sourcecode]
24. Now for MySQL. If you have a previous version of MySQL installed, you probably have the old MySQL preference pane, which doesn't work under Snow Leopard. Fortunately swoon.net has recompiled a 64-bit version. Grab it and install it. Then pop into System Preferences and stop your MySQL server if it's running.
25. Given that there are prebuilt x64 binaries for OS X, I don't feel any particular need to build MySQL from scratch. I've found anything past MySQL 5.1 to be problematic for Rails.
MySQL Download Page
Pick a mirror and download the "Mac OS X 10.5 (x86_64)" version. Mount the dmg and run the MySQL package and then the MySQL startup item package. Then start MySQL:
[sourcecode language='bash']
sudo /Library/StartupItems/MySQLCOM/MySQLCOM start
[/sourcecode]
26. If you have existing MySQL databases to bring over from an old version, see the instructions from edward - remember to change the old directory name to match the version you were running before.
27. SQLite and MySQL are nice, but these days I’m using PostgreSQL for new Rails work. If you want a shortcut, there’s an installer that runs on OS X: grab it and run it. But to get best performance, you probably should build by hand. There are good instructions from Tyler Hunt for that, though you need to update the download version. Don’t install the postgres gem though; it’s slow and outdated, and anyhow there’s still work to do to get gems set up.
PostgreSQL source code
[sourcecode language='bash']
wget ftp://ftp.postgresql.org/pub/source/v8.4.0/postgresql-8.4.0.tar.gz
tar -xvzf postgresql-8.4.0.tar.gz
cd postgresql-8.4.0
./configure --enable-thread-safety --with-bonjour
[/sourcecode]
And follow Tyler's instructions from there for installing, creating a group and user, and hooking up launchd.
28. Reload your old PostgreSQL databases.
29. Databases in hand, let’s turn to ruby. Given that I expect a transition to ruby 1.9 over the next year, and I find myself wanting to test on odd rubies from time to time, I’m going to completely ignore the system ruby except to bootstrap a multiruby setup. Fortunately, the recently-released Ruby Version Manager is working great already.
Ruby Version Manager homepage
[sourcecode language='bash']
sudo gem install rvm
rvm-install
rvm install 1.8.6 -C --enable-shared,--with-readline-dir=/usr/local
rvm install 1.8.7 -C --enable-shared,--with-readline-dir=/usr/local
rvm install 1.9.1 -C --enable-shared,--with-readline-dir=/usr/local
rvm install 1.9.2 -C --enable-shared,--with-readline-dir=/usr/local
rvm 1.8.7 --default
[/sourcecode]
I'm skipping REE, JRuby, and Rubinius for the moment, but will likely add them to the system later.
30. Time to install the two problematic gems. I’m just going to do this under 1.8.7 for now, but will update the other rubies later.
MySQL: (from Greg Benedict)
[sourcecode language='bash']
sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
[/sourcecode]
PostgreSQL: (from iCoreTech)
[sourcecode language='ruby']
sudo -s
export ARCHFLAGS='-arch x86_64'
export PATH=/usr/local/pgsql/bin:${PATH}
gem install pg
exit
[/sourcecode]
31. The rest of the gems should be easier. Grab the gemlist.txt file you created way back at the start and edit it to one gem name per line. Ditch anything you know you don’t need. Then fire up IRB and run:
[sourcecode language='ruby']
File.open('/Users/mike/gemlist.txt').each_line {|line| `sudo gem install #{line.split.first}`}
[/sourcecode]
Obviously change the file name to match where you put it on your own drive.
This could use some tweaking to deliver feedback.
[stalled at RedCloth?]
32. This is a good time to get git on the system. Fortunately, there’s an easy and functional OS X installer for that. Download, mount the disk image, and run the installer and shell script.
33. imagemagick used to be a bear, but at the moment there’s a good install script for it on GitHub. So, now that you have your shiny new copy of git:
[sourcecode language='bash']
git clone git://github.com/maddox/magick-installer.git
cd magick-installer/
./magick-installer.sh
[/sourcecode]
34. I also need memcached locally. Wincent has good install instructions:
[sourcecode language='bash']
wget http://www.monkey.org/~provos/libevent-1.4.12-stable.tar.gz
tar xvzf libevent-1.4.12-stable.tar.gz
cd libevent-1.4.12-stable
./configure
make
sudo make install
wget http://memcached.googlecode.com/files/memcached-1.4.1.tar.gz
tar xvzf memcached-1.4.1.tar.gz
cd memcached-1.4.1
./configure
make
sudo make install
[/sourcecode]
35. I’d like to run gem server locally on a startup basis to handle my gem RDoc needs, but I need to figure out how (or whether) that can be made to play nicely with rvm. Meanwhile, bdoc is an acceptable alternative:
[sourcecode language='bash']
sudo gem install manalang-bdoc
[/sourcecode]
36. Finally (for now!) I prefer most as a pager to less or more. It supports paging forwards and backwards, split windows, and can even drop the file you're paging right into your editor of choice.
Most home page
You’ll need some prerequisites first:
pcre:
[sourcecode language='bash']
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz
tar xvzf pcre-7.9.tar.gz
cd pcre-7.9
./configure
make
sudo make install
[/sourcecode]
Oniguruma:
[sourcecode language='bash']
wget http://www.geocities.jp/kosako3/oniguruma/archive/onig-5.9.1.tar.gz
tar xvzf onig-5.9.1.tar.gz
cd onig-5.9.1
./configure
make
sudo make install
[/sourcecode]
S-Lang:
[sourcecode language='bash']
wget ftp://space.mit.edu/pub/davis/slang/v2.2/slang-2.2.0.tar.gz
tar xvzf slang-2.2.0.tar.gz
cd slang-2.2.0
./configure
make
sudo make install
[/sourcecode]
And now most at last:
[sourcecode language='bash']
wget ftp://space.mit.edu/pub/davis/most/most-5.0.0.tar.gz
tar xvzf most-5.0.0.tar.gz
cd most-5.0.0
./configure
make
sudo make install
[/sourcecode]
And there you have it! Start to finish, this process took me about 3 hours on a MacBook Pro with around 90GB of data that I wanted to save. I expect it to take much longer on the desktop with the correspondingly larger hard drive, but much of that will be overnight backup and restore times. If you have any tweaks and suggestions, feel free to add them to the comments.