Last Updated: February 25, 2016
· esanin

PostgreSQL, Rails and OS X

As a brand new Rails developer one of the first things I had to do was to set up my dev environment in Mountain Lion (OS X is something I'm also new at, by the way). Overall, installing Ruby and installing Rails was an easy experience, but PostgreSQL wasn't as easy:

To me, the best way to install PostgreSQL is with Homebrew:

$> brew install postgresql

When that command is done, it will give you some instructions about creating creating a database. The command should be something like this:
$> initdb /usr/local/var/postgres -E utf8

To validate that everything is working properly, you should run postgre's interactive console:

$> psql

If it connects, awesome! Postgres was installed successfuly. Sadly, I quickly learned that it doesn't mean your Rails app will connect to the database and I got this message:

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

I googled the problem for a while and couldn't find a solution for it. I didn't have problems with my $PATH and creating a symbolic link didn't fix the problem either. However, this comment set me on the right path.

$> gem uninstall pg
$> gem install pg

So... the solution is to reinstall the pg gem? Yup, at least for me. Mountain Lion comes with PostgreSQL pre-installed, so if you set up your Rails environment and installed the gem before installing postgres with homebrew, the gem will be pointing to that pre-installed version, not the one you actually want to use. Re-installing pg will make it point to your freshly installed postgres.

3 Responses
Add your response

Then there is

over 1 year ago ·

True, but I only learned about it after dealing with postgres & homebrew.

I know some people who have ran into the same problem with, but I haven't looked into it.

over 1 year ago ·

I had the same problem using

over 1 year ago ·