My goal is pretty simple. I want to use my favorite database PostgreSQL, with my favorite environment (Ruby on Rails), on my favorite OS (Mac OSX). Unfortunately, this wasn’t as straight-forward as I could have hoped. After shifting through various conflicting and inconclusive sources of information including the occasionally cryptic Ruby Wiki and the Postgresql docs, I decided that I’d try to condense this information down for those of us that just want to write some code. I found the easiest and most trouble free way to do this is to install Mac Ports. Their instructions are good and make sense, so there is no need to elaborate here. Just make sure you have Xcode installed. With that out of the way, to install Postgresql type:
sudo port install postgresql82 postgresql82-serverAlong with installing postgres, it’ll put up a bunch of instructions about how to install postgres as a service, and create a new database. Unlike normal unix installs, the default postgres user is postgres82. The next step is to update Ruby, since the Ruby that is shipped with Tiger is broken. The simplest way is to use ports again:
sudo port install ruby rb-rubygemsYou might need to add /opt/local/bin to your PATH environment variable in order to use your updated Ruby instead of the system one. Next, install Rails with:
sudo gem install rails -yNow for the final and most complicated step, installing a Postgres ruby driver. There are two available drivers, a native one and a pure ruby implementation. For performance reasons, the native driver is preferred, however it is a little unintuitive to install. You first need to set some environment variables (these examples assume the bash shell): If you miss that step, you’ll receive numerous errors from gcc. The final step is (as root):
POSTGRES_INCLUDE=/opt/local/include/postgresql82 gem install postgres -- --with-pgsql-lib-dir=/opt/local/lib/postgresql82At this point, you should be ready to start developing your Rails apps against Postgres.
Did you like this? Please share:
The Lost Year: A Failed Experiment to Switch Away From Mac
Fed up with the Apple Keyboard, I bought a ThinkPad, installed Linux, and promptly decided that I hated computers.
Maker's Space, Manager's Space
The Grand Remote Work Experiment: A Retrospective
The COVID-19 pandemic has lead to an unexpected experiment in remote working. What has worked and why?