How to Install PostgreSQL on Windows, Mac, and Linux

Learn how to install PostgreSQL on Windows, macOS, and Linux with our step-by-step guide. Get started with this powerful open-source database today!

Updated: 29 Jun, 23 by Susith Nonis 7 Min

List of content you will read in this article:

PostgreSQL is a popular open-source relational database management system (RDBMS) widely used by developers and businesses. Whether you're a developer looking to create powerful data-driven applications or an organization looking to manage large amounts of data, PostgreSQL is an excellent choice. This article will guide you through installing PostgreSQL on Windows, macOS, and Linux. So, if you're ready to start with PostgreSQL, let's dive in!

PostgreSQL is a powerful open-source relational database management system (RDBMS) known for its robustness, scalability, and high performance. It works by storing data in tables, which are organized into schemas. Each table contains rows and columns, with each column representing an attribute of the data being stored. PostgreSQL uses SQL (Structured Query Language) to manipulate table data. SQL provides a standard way to communicate with the database and is widely used for data retrieval and manipulation.

PostgreSQL also incorporates advanced features such as queries that support advanced indexing and partitioning, allowing developers to retrieve data from large datasets efficiently. Additionally, the system supports a wide range of programming languages and frameworks, making it a versatile and flexible choice for developers working on various projects. With its strong emphasis on reliability, security, and data integrity, PostgreSQL has become a popular choice for businesses and organizations that must manage large amounts of data.

Installing PostgreSQL on Windows is a straightforward process that can be completed in just a few simple steps. Here's a step-by-step guide to help you get started:

  1. Download the PostgreSQL installer from the official website. 
  2. Once the download is complete, run the installer by double-clicking on the downloaded file.
  3. The first screen that appears is the PostgreSQL Setup Wizard. Click "Next" to proceed.
  4. On the next screen, review the license agreement, then click "Next" to accept the terms and conditions.
  5. The following screen allows you to choose the installation directory. We recommend using the default directory unless you have a specific reason to change the installation directory. Click "Next" to proceed.
  6. On the next screen, you will be asked to choose the components to install. We recommend leaving all the checkboxes selected unless you need to change the components. Click "Next" to proceed.
  7. The next screen asks you to choose the PostgreSQL data directory. By default, this is set to C:\Program Files\PostgreSQL\\data. We recommend using the default setting unless you need to change the data directory. Click "Next" to proceed.
  8. On the next screen, you will be asked to create a password for the PostgreSQL superuser (postgres). Enter a strong password, then click "Next" to proceed.
  9. The next screen will ask you to choose the port number that PostgreSQL will use. Unless you have a specific reason to change the port number, we recommend using the default setting (5432). Click "Next" to proceed.
  10. On the next screen, review the installation summary, then click "Next" to start the installation.
  11. Once the installation is complete, click "Finish" to close the wizard.

Congratulations! You have now installed PostgreSQL on your Windows machine. You can now start using PostgreSQL by launching pgAdmin, which should be installed along with PostgreSQL.

To install PostgreSQL on macOS, you’ll need to use the Terminal app, but the process is as easy as copying and running a few commands:

  • Open the Terminal application on your Mac.
  • Install Homebrew on your Mac by running the following command: 

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  • Once Homebrew is installed, update it by running the command:

brew update

  • Install PostgreSQL by running the command:

brew install postgresql

  • After installing PostgreSQL, you can start the database server by running the command:

pg_ctl -D /usr/local/var/postgres start

  • To test if PostgreSQL is working correctly, open psql by running the command:

psql

  • You should see a prompt that looks like this:

psql (12.2)

Type "help" for help.

  • You can test that PostgreSQL is working by creating a test database by running the following command in the psql prompt:

CREATE DATABASE testdb;

  • You can list all the databases by running the command:

\list

  • When you are finished working with PostgreSQL, you can stop the database server by running the command:

pg_ctl -D /usr/local/var/postgres stop

Congratulations! You have successfully installed PostgreSQL on your Mac.

Like macOS, Linux requires you to run a few terminal commands to install PostgreSQL. Here’s how:

Here is a step-by-step guide on how to install PostgreSQL on Linux:

  • Open a terminal prompt.
  • Update the package list by running the following command:

sudo apt-get update

  • Install PostgreSQL by running the command:

sudo apt-get install postgresql postgresql-contrib

  • PostgreSQL should start automatically after installation. If it doesn't start, run the following command to start it:

sudo service postgresql start

  • PostgreSQL is secure by default, so the default user "postgres" is the only user that can access the database. To access the PostgreSQL prompt, you will need to switch to this user using the following command:

sudo -i -u postgres

  • From here, you can start the PostgreSQL command prompt by typing:

psql

  • Create a new user account by typing:

CREATE USER myusername WITH PASSWORD 'mypassword';

  • Create a new database by typing:

CREATE DATABASE mydatabase;

  • Grant the new user full access to the new database by typing:

GRANT ALL PRIVILEGES ON DATABASE mydatabase TO myusername;

  • Quit the PostgreSQL prompt by typing:

\q

Congratulations! You have successfully installed and configured PostgreSQL on your Linux machine.

In conclusion, installing PostgreSQL on Windows, Mac, and Linux can be a straightforward and seamless process with the right guidance. Following the step-by-step guides provided for each operating system, users can successfully download, install, and configure PostgreSQL to meet their database needs. With PostgreSQL's versatility, security, and scalability, users can use its features for various applications, from small-scale projects to large-scale enterprise-level operations. Whether you are a developer or a business owner, PostgreSQL can be a valuable tool in managing and processing data, and installing it on your desired operating system is the first step toward utilizing its benefits.

  • PostgreSQL is a popular open-source relational database management system that runs on Windows, Mac, and Linux.
  • Installing PostgreSQL on these operating systems involves downloading the installer and following the steps in the installation wizard.
  • Users can install PostgreSQL on Windows using the graphical installer or the command-line installer.
  • PostgreSQL can be installed on Mac using the Homebrew package manager or by downloading the installer from the official website.
  • On Linux, users can install PostgreSQL from the default package manager or download the installer from the official website.

People also read:

The latest version of PostgreSQL at the time of writing is 15.2, released on February 9, 2023.

Yes, PostgreSQL can be installed on multiple computers, allowing for distributed database management.

No, you need not be a system administrator to install PostgreSQL. However, you do need to have administrative privileges on the computer.

Yes, PostgreSQL can be installed on a virtual machine, allowing for increased flexibility and scalability in managing databases.

PostgreSQL is designed to be compatible with most operating systems and software environments, but checking the documentation for any potential compatibility issues is always recommended before installing.

Susith Nonis

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.