Skip to content

Instantly share code, notes, and snippets.

Last active July 11, 2024 20:06
Show Gist options
  • Save p1nox/4953113 to your computer and use it in GitHub Desktop.
Save p1nox/4953113 to your computer and use it in GitHub Desktop.
PostgreSQL configuration without password on Ubuntu for Rails


You could have postgre installed on localhost with password (or without user or password seted after instalation) but if we are developing we really don't need password, so configuring postgre server without password for all your rails project is usefull.

Install Postgre packages

  • postgresql
  • postgresql-client
  • libpq-dev

Install Postgre gem


gem 'pg'


  1. Edit postgre configuration file:

     sudo gedit /etc/postgresql/POSTGRE_VERSION/main/pg_hba.conf
  2. Change all configuration access to:

     # Database administrative login by Unix domain socket
     local   all             all                                     trust
     # TYPE  DATABASE        USER            ADDRESS                 METHOD
     # "local" is for Unix domain socket connections only
     local   all             all                                     trust
     # IPv4 local connections:
     host    all             all               trust
     # IPv6 local connections:
     host    all             all             ::1/128                 trust
  3. Restart postgre server

     sudo /etc/init.d/postgresql restart
  4. Enjoy :)

Copy link

pori commented Nov 13, 2014

Thanks! Running a rails app with trust authentication is surprisingly hard to find help for. You're a lifesaver.

Copy link

omkz commented Oct 6, 2016

thank you! it's work

Copy link

Epigene commented Oct 14, 2017

Worked like a charm!

Copy link

Seralto commented Oct 24, 2017

Very good!

Copy link

jorgeacaballero commented Oct 28, 2017

Nice! Works as expected. Thanks for this. As a user in macos, this is a lifesaver.

Copy link

thank you so much! it was very helpful!

Copy link

thanks! )

Copy link

excuse me ,I failed to install. Can you tell me the command of the second step?

Copy link

Thank you!!

Copy link

Tcalura commented Jul 26, 2019

Thank you and congrats for the content you made.

Copy link

lastab commented Jan 7, 2020

Thanks! It worked.

Copy link

Thank you! I created a rails app without --database=postgresql and trying to rails db:create postgres in development was impossible for me without this!

Copy link

Thank you!

Copy link

54keesh commented Dec 12, 2022

works like a charm:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment