How To Download And Configure PostgreSQL For Rails On Your Mac

If you’ve played around with Ruby on Rails, you might have noticed that Rails comes with SQLite3 as your test / development database, while Heroku defaults to PostgreSQL in production.

This is not surprising, considering how hard it is to install PostgreSQL compared to SQLite3. However, since you’re not testing / developing in completely the same environment as production, you’re putting yourself in a position for some possibly nasty surprises (in case you can’t tell, I’ve definitely faced these already, even with my small apps!).

Luckily, there is now a simpler way to install and configure PostgreSQL if you haven’t ever downloaded it on your Mac before brought you by Ruby on Rails developer Gavin Morgan:

Here are the steps to follow to get PostgreSQL downloaded and running with your Rails application:

  1. Visit & download the app.
  2. Install & run the app.
  3. Execute “$ psql -h localhost” to enter local psql terminal.
  4. Execute “=# select * from pg_roles;” to list the accounts w/ access privelages.
  5. Execute “$ rails new myApp -d postgresql” to create psql rails app.
  6. Fix config/database.yml to include your psql credentials — ‘username‘and ‘password’ (you can leave the password blank if you don’t remember it).
  7. Fit ‘host: localhost‘ into config/database.yml under ‘test:’ & ‘development:
  8. Note: Heroku is gonna throw database.yml away & use its own settings.
  9. Execute “$ rake db:create:all” to create your psql databases.

Note: If you have installed PostgreSQL before via ‘$brew install postgresql’ and it’s not working for you, find someone more experienced to help you make it work. Today, I got help from co-founder Dave Paolo, who performed a lot of magic and sorcery to delete the installed version of PostgreSQL from my machine so I can re-download it!

Enjoy the article? Join over 17,500+ Swift developers and enthusiasts who get my weekly updates.