Ruby on Rails and PostgreSQL on Snow Leopard
Upgrading from 10.5 to 10.6 last night was painless. I got back well over 10gb of space on my drive, and everything feels zippier. Hooray! Unfortunately, Snow Leopard completely trashed my Rails development setup. When I tried to run script/server, I was greeted with various gems barfing all over the place.
Here’s how I fixed my setup (YMMV, not responsible for any loss or damage, etc.):
First Things First
I had to install the Xcode.mpkg package from the Optional Installs folder of the Snow Leopard installation DVD. No problems here.
I then needed to rebuild all of my gems with:
'gem pristine --all'
PostgreSQL
The previous step blew up when it got to the ‘postgres’ gem with:
ERROR: Error installing postgres: ERROR: Failed to build gem native extension.
I had installed PostgreSQL on Leopard with the now outdated one-click installer, so I removed all of that using the included uninstaller, found in /Library/PostgreSQL/8.3/. Of course, please back up all your important databases first.
I installed the latest version of MacPorts from http://www.macports.org/install.php (1.8.0 at the time of writing) and then followed some of the steps from this article to get PostgreSQL up and running. Those boiled down to:
sudo port install postgresql83 postgresql83-server
sudo mkdir -p /opt/local/var/db/postgresql83/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql83/defaultdb
sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb'
sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist
I rebooted to start PostgreSQL, opened up ~/.bash_profile and added /opt/local/lib/postgresql83/bin/ to my PATH, then reloaded the file with:
source ~/.bash_profile
Now I was able to rebuild my gems, but I had to include the architecture type, otherwise ‘postgres’ would barf again.
sudo env ARCHFLAGS="-arch x86_64" gem pristine --all
Rubynode and Gem Install Path
Oh great, another gem failed. This time it was rubynode. I don’t use it, so I tried to uninstall it, but got:
ERROR: While executing gem ... (Gem::InstallError)
cannot uninstall, check `gem list -d rubynode`
Very strange considering the output I got from my gem list was this:
gem list -d rubynode
*** LOCAL GEMS ***
rubynode (0.1.5)
Author: Dominik Bathon
Homepage: http://rubynode.rubyforge.org/
Installed at: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
RubyNode is a library that allows read only access to Ruby's internal NODE structure.
After some research I found out I needed to manually specify the install path:
sudo gem uninstall --install-dir /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 rubynode
Successfully uninstalled rubynode-0.1.5
I once again ran:
sudo env ARCHFLAGS="-arch x86_64" gem pristine --all
Everything seemed to be working at that point, but there were a couple of steps left.
PL/pgSQL Language
When I tried to run our development bootstrapping script I got this back:
ERROR: language "plpgsql" does not exist
All I needed to do was add that language to the template1 database so that all new databases would receive that language by default. The command (in the shell, not SQL) is simply:
createlang plpgsql template1
Ruby 1.8.7 Pitfalls
Another important thing to note is that Snow Leopard pushes Ruby up from 1.8.6 to 1.8.7. This won’t be a problem for most people, but I ran into one major snag.
undefined method `length’ for Enumerable Enumerator on text_helper.rb:50:in `truncate’
I found a simple workaround here that suggests adding the following to environment.rb. It worked nicely.
module ActionView
module Helpers
module TextHelper
def truncate(text, length = 30, truncate_string = "...")
if text.nil? then return end
l = length - truncate_string.chars.to_a.size
(text.chars.to_a.size > length ? text.chars.to_a[0...l].join + truncate_string : text).to_s
end
end
end
end
I’ll update this article with anything else that comes up, but for now everything seems to be working and I can get back to writing code.
/07:41 PM