If you’re working on a Node.js project and run into errors like ECONNREFUSED ::1:5432
, chances are PostgreSQL isn’t running — or it isn’t even installed. Here’s a quick guide to install postgres on macOS using Homebrew, the most reliable and straightforward method.
Before installing PostgreSQL, make sure you already have Homebrew installed on your Mac. Homebrew is the package manager we’ll be using to install and manage PostgreSQL.
Don’t have Homebrew yet? No worries, we got you covered. Check out our guide: How to Install Homebrew on macOS.
Once you’ve got Homebrew set up, you’re ready to continue.
Step 1: Install PostgreSQL via Homebrew
With Homebrew installed, adding PostgreSQL is easy:
brew install postgresql
BashIf you want to install a specific version of postgres, e.g, version 17 type:
brew install postgresql@17
BashStep 2: Start the PostgreSQL Service
Once installed, start PostgreSQL as a background service:
brew services start postgresql
BashTo confirm it’s running:
brew services list
BashYou should see something like:
Name Status User File
postgresql started your-name Library/LaunchAgents/[email protected]
BashStep 4: Confirm the Installation
Check that PostgreSQL is installed correctly:
psql --version
BashExpected output:
psql (PostgreSQL) 17.5 (Homebrew)
BashIn case you are getting a command not found: psql
error you have to explicitly link it. For my example, in which i installed version 17, I just had to type
brew link postgresql@17 --force
BashBy typing psql --version
you should now see the postgreSQL you just installed.
Step 5: Connect to PostgreSQL
You can now open a PostgreSQL shell:
psql postgres
BashOr create your own database:
createdb mydb
psql mydb
BashStep 6 (Optional): Choosing a GUI
If you prefer a graphical interface over the terminal, consider installing
These tools make managing your databases even easier.
Leave a reply