Skip to content

Instantly share code, notes, and snippets.

@PurityControl
Last active August 20, 2016 09:40
Show Gist options
  • Save PurityControl/72c00777af9a34f85dff3c5bd49d2a60 to your computer and use it in GitHub Desktop.
Save PurityControl/72c00777af9a34f85dff3c5bd49d2a60 to your computer and use it in GitHub Desktop.
Install postgres on mac using ports and compile ruby pg gem
# set the version of postgresql for future commands
PG_VER=95

# install from ports
sudo port install postgresql$(PG_VER)-server

# initialize the database -> described in ports output
sudo mkdir -p /opt/local/var/db/postgresql$(PG_VER)/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql$(PG_VER)/defaultdb
sudo su postgres -c '/opt/local/lib/postgresql$(PG_VER)/bin/initdb -D /opt/local/var/db/postgresql$(PG_VER)/defaultdb' 
sudo -u _postgres /opt/local/lib/postgresql$(PG_VER)/bin/pg_ctl -D /opt/local/var/db/postgresql$(PG_VER)/defaultdb -l logfile start

# make postgresql launch on startup
sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql95-server.plist

# link the psql app in your home bin folder
ln -s /opt/local/bin/psql95 ~/bin/psql

# create a new superuser
/opt/local/lib/postgresql$(PG_VER)/bin/createuser -U postgres -s new_user_name

# create a new database
/opt/local/lib/postgresql$(PG_VER)/bin/createdb new_database

# add the location of the postgresql binaries to your path (optional)
export PATH=$PATH:/opt/local/lib/postgresql$(PG_VER)/bin

# install the pg gem in ruby
gem install pg -- --with-pg-lib=/opt/local/lib/postgresql$(PG_VER) --with-pg-include=/opt/local/include/postgresql$(PG_VER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment