Home » Blog » How to install postgres on MacOS
How to install postgres on MacOS

How to install postgres on MacOS

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
Bash

If you want to install a specific version of postgres, e.g, version 17 type:

brew install postgresql@17       
Bash

Step 2: Start the PostgreSQL Service

Once installed, start PostgreSQL as a background service:

brew services start postgresql
Bash

To confirm it’s running:

brew services list
Bash

You should see something like:

Name        Status   User       File
postgresql  started  your-name  Library/LaunchAgents/[email protected]
Bash

Step 4: Confirm the Installation

Check that PostgreSQL is installed correctly:

psql --version
Bash

Expected output:

psql (PostgreSQL) 17.5 (Homebrew)
Bash

In 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
Bash

By 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
Bash

Or create your own database:

createdb mydb
psql mydb
Bash

Step 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

Your email address will not be published. Required fields are marked *