How to Install PostgreSQL on a Mac with Homebrew
Last Updated :
04 Apr, 2025
Homebrew is a popular manager that is used for the installation of different types of software in the Mac as well as Linux operating systems. we can use Homebrew for installing other software instead of running specific commands. This improves the security as compared to not using homebrew for the installation of applications.
This is a step-by-step article where we are going to understand, how we can install PostgreSQL on a Mac operating system using homebrew.
How to Install PostgreSQL on a Mac with Homebrew
PostgreSQL is a popular relational database management system (DBMS) which is also known as Postgres, it is open-source and uses the compliance of SQL for its internal working.
It is an open-source software which is developed by Max Howell and it uses GitHub for giving the packages to the users. before using the homebrew for installing the PostgreSQL we will have to install homebrew on the Mac, following are the steps for installing homebrew:
Step 1: Install Homebrew
Open the terminal and type the following command to install the homebrew from a package source. This will show us the different components of homebrew which will be installed.
/bin/bash -c "$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Output:
homebrew installation.Once homebrew is installed, we can run the homebrew and install PostgreSQL but if you already had homebrew installed before then you can follow step 2 to update it.
Step 2: Update Homebrew
It is important to update the homebrew because from time to time we get updates of homebrew for latest packages and features so before installing any software we must update the homebrew to the latest version.
brew update
Output:
brew update.Once the homebrew is successfully installed, there are some important steps that we need to follow for the successful installation of PostgreSQL if we are using homebrew, these steps are as follows:
1. Download the PostgreSQL installer for Mac.
2. Installing PostgreSQL.
3. Verify the installation.
Let's understand each of these steps one by one.
Step 3: Install Postgres
For downloading and installing the PostgreSQL, we will have to run the following command in the terminal as you can see in the image as well
brew install postgresql
Output:
brew install postgresqlOnce the PostgreSQL is installed, we can check its installation by running some commands, it takes some time to successfully install PostgreSQL in the mac using homebrew so be patient. Once it is installed, it will show you the next steps and commands for starting the service, as visible in the image below:
brew services start postgresqlOnce we run this command we can start the PostgreSQL, it requires us to create a role with user and password along with it so that we can establish connection to the database.
Step 4: Start the Postgres service
In this step, we will create a user and also create a database which will be assigned to that particular user to test whether PostgreSQL is successfully installed with homebrew or not. following are the steps for this:
Step 1: Start Postgresql:
First step is to start the PostgreSQL service, for this we can simply type the psql postgres command and it will start the PostgreSQL service for us. Once the service is started we will see that profile name disappears and instead postgres appears in the terminal.
Output:
Start PostgresqlStep 2: Create Role With Password:
The next step is to create a role with password, for this we will have to follow the following syntax:
CREATE ROLE role_name WITH LOGIN PASSWORD password_for_user;
As you can see in the image below, we have followed the same above syntax to create a user named app_user with password as app_password.
Output:
Create Role With Password.Step 3: Alter Role for User:
Next step is to alter the role for the user that we have created, role altering means that we are assigning a different role to the user so that the user can perform necessary tasks with admin privileges.
As you can see in the image below, we are assigning the user with the role of CREATEDB which means that the user can create database.
Output:
Alter Role for User.Step 4: Create Database:
In this next step we will create a database, for creating a database we will first have to login with the user's details that we have created. Simply type psql postgres -U username to login as the user.
Then we will create database with following syntax, as you can see in the image below.
CREATE DATABASE database_name;
Output:
Create Database.After creating the database we can run the /l command which will list the databases that we have created, as you can see in the first option we have the app_database that we just created.
This is how we can install PostgreSQL on a mac using homebrew, by following these steps we can easily install the PostgreSQL in any mac system.
Troubleshooting
- Sometimes we may have to perform some troubleshooting of the postgresql because there may be some errors in it.
- The troubleshooting of postgresql involves solving different issues which can be related to performance or the connection of database as well.
- Whenever we try to troubleshoot the problem of PostgreSQL, we should look at the logs of the PostgreSQL first.
- PostgreSQL logs are a built in feature of the software which allows us to look at the detailed information about the errors and any issues if they come and interrupt the process.
- Troubleshooting these issues are important because it can also result in data corruption as well as crashes, if these issues are not managed properly.
- For troubleshooting this we can take a look at the logs and the system environment to analyze the issues.
Conclusion
Homebrew can be used for installing postgresql in the mac operating system, for this we will have to first install homebrew in the system and then use the brew install PostgreSQL command to install PostgreSQL in the system. By following each of the steps we can install and manage the database in the PostgreSQL.
Similar Reads
How to Install PyGreSQL in MacOS?
PyGreSQL is a Python library that provides an easy-to-use interface for connecting with PostgreSQL databases. In this article, we discuss the process of installing PyGreSQL on macOS. In which we will learn different methods to install PyGreSQL and verify the installation. This article will be helpfu
2 min read
How to Install SQL Server Agent on MacOS?
SQL Server is a Relational Database Management system(RDBMS) developed by Microsoft. SQL Server consists of two major components namely Database Engine and SQLOS. Along with the creation and execution of triggers Database Engine also processes queries and manages Database fields. SQLOS provides serv
2 min read
Install PostgreSQL on Mac
Installing PostgreSQL on Mac OS can enhance our development environment, providing a robust relational database management system. In this article, we will focus on installing PostgreSQL version 11.3 using the installer provided by EnterpriseDB. This step-by-step guide will ensure a smooth installat
4 min read
How to Install SQL Developer on MacOS?
Oracle SQL Developer is a free, integrated development environment that optimizes Oracle Database development and management in both traditional and cloud deployments. SQL Developer provides complete end-to-end development of your PL/SQL applications, a spreadsheet for running queries and scripts, a
2 min read
How to Install SQL Server on MacOS?
In this article, we are going to learn "How to install SQL Server Express in MacOs". Now, before we jump to the setup part, Let's learn about SQL Server Express. So, SQL Server Express is an open-source RDBMS database management system i.e. Relational database management system which is used to stor
5 min read
How to install Django with NGINX, Gunicorn, and PostgreSQL on Ubuntu?
This article describes how to install and configure Django with PostgreSQL, Gunicorn, and Nginx on your Ubuntu machine. First, let's look at an overview of all the tools we use. Django is a robust, free, open-source, Python-based web framework that follows the MVT (Model-Template-View) architectural
6 min read
How to Install PHP Composer on MacOS?
A composer is a tool for dependency manager in PHP. It is an important package manager for PHP. The package manager means it allows anyone to import codebases into the project and keep them updated and also helps in managing dependencies. Or we can say that it allows users to install the required li
2 min read
How to Install Dart Sass on MacOS?
Dart Sass is a programming language developed by Google used to build server and desktop applications. Dart is an object-oriented, class-based, language. Sass in Dart Sass stands for Syntactically Awesome Stylesheets. Dart Sass brings in the power of basic scripting tools such as variables and loops
2 min read
How to Install OpenCV for C++ on MacOS?
OpenCV stands for Open Source Computer and Vision Library. It is a huge open-source library with more than 2500 algorithms that are optimized to perform various operations like computer vision, image processing, and machine learning in real-time. It performs all these operations in real-time which g
4 min read
How to install sqlite3 for Ruby on MacOS?
In this article, we are going learn how to install SQLite3 for Ruby on MacOS. There are various methods to install SQLite3 for Ruby on MacOS we are going to cover all of them. What is SQLite3?SQLite3 is a versatile and lightweight relational database management system (RDBMS) that plays a pivotal ro
4 min read