Postgres.app

The easiest way to get started with PostgreSQL on the Mac

To install the pg gem, make sure you have set up your $PATH correctly (see Command-Line Tools), then execute the following command:

sudo ARCHFLAGS="-arch x86_64" gem install pg

If you are running your application with Foreman, set the DATABASE_URL config variable in .env:

DATABASE_URL=postgres://postgres@localhost/[YOUR_DATABASE_NAME]

You can learn more about environment variables from this Heroku Dev Center article.

Rails

In config/database.yml, use the following settings:

development:
  adapter: postgresql
  database: [YOUR_DATABASE_NAME]
  host: localhost

Sinatra

In config.ru or your application code:

set :database, ENV['DATABASE_URL'] || 'postgres://localhost/[YOUR_DATABASE_NAME]'

ActiveRecord

Install the activerecord gem and require 'active_record', and establish a database connection:

ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"])

DataMapper

Install and require the datamapper and do_postgres gems, and create a database connection:

DataMapper.setup(:default, ENV['DATABASE_URL'] || "postgres://localhost/[YOUR_DATABASE_NAME]")

Sequel

Install and require the sequel gem, and create a database connection:

DB = Sequel.connect(ENV['DATABASE_URL'] || "postgres://localhost/[YOUR_DATABASE_NAME]")