Installing PostgreSQL on Leopard using MacPorts
Now I don't want to go too deep into this, so I'm going to assume that if you are reading this, that you have the following installed
So now that you have all of those dependencies out of the way, let's get to installing us some PostgreSQL.
To install the database software, simply run the following command in Terminal
sudo port install \ postgresql83 \ postgresql83-server
This will install the client and server needed for you to run this on your machine. Now pay special attention to the installation script. At the end of installation processes, macports will display a message for you that contains some commands for you to get started with.
First, execute these lines of code. This will setup a new database for you to play with
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'
Start PostgreSQL Automatically
By running the next command, you can have PostgreSQL lunch automatically so that it's always available to you
sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist
pgAdmin III is a PostgreSQL management and administrations piece of software. It's a nice GUI to some things that you may find yourself wanting to do, like created databases and whatnot. Installation of this is pretty cake.
sudo port install pgAdmin3
Upon completion of installation, you can find the application in
PostgreSQL Libraries for Ruby via Gems
I have to admit, the previous installation steps were nothing to cry about; however, it was this step that made me want to put together this little walkthrough.
sudo env ARCHFLAGS="-arch i386" \ gem install postgres -- \ --with-pgsql-lib=/opt/local/lib/postgresql83 \ --with-pgsql-include=/opt/local/include/postgresql83
That's not exactly your everyday
gem install command. For one, the environment variable
ARCHFLAGS has to be set. Secondly, the
gem command needs to know where the PostgreSQL libraries and include headers are so that it can compile. Looking back, it's actually quite easy to copy and paste that command, it just took me a while to find out exactly what I needed to make it work.
Well, I hope that helps anyone looking to install and setup PostgreSQL in Leopard. Until next time...