Install PostgreSQL on Ubuntu, Windows, and Mac

Learn via video courses
Topics Covered

Overview

PostgreSQL is an open-source relational database management system. PostgreSQL is a database management system that is known for its extensibility, SQL compliance, and robustness features. Both relational(SQL) and non-relational(JSON) queries are supported by PostgreSQL. In this article, we will learn the steps of PostgreSQL installation for Windows, Mac, and Ubuntu.

How to Install PostgreSQL on Windows?

Download PostgreSQL Installer for Windows

Step - 1:

Open the download page of PostgreSQL installers on the EnterpriseDB.

Step - 2:

Now on this page click on the download option available for the windows, as shown below figure.

downloading postgresql for windowsx86-64

Step - 3:

After some time PostgreSQL will be downloaded in your system.

Install PostgreSQL on Windows Step-by-step

Administrator privileges are required for PostgreSQL installation on Windows.

Step - 1:

Open the installer file by double-clicking it, now the installation wizard will open on your screen, now click on the next button.

Step - 2:

Click on the next.

clicking on next button to setup postgresql in windows

Step - 3:

Now select the folder for Postgresql installation, you can specify any custom path or you can keep the folder by default selected by Postgresql, then click on the next.

selecting folder for setup of postgresql in windows

Step - 4:

Now a window will open that will ask for a selection of different software components, select only those that you want to install:

  • PostgreSQL server is installed for the Postgresql database server installation.
  • pgAdmin 4 is installed to use GUI for database management.
  • Stack Builder is installed to get a GUI for the installation of different drivers for Postgresql.
  • Command line tools are installed for working with different command line tools like pg_restore, psql, etc. With these tools, you can use the command line for interaction with Postgresql.

Select all except Stack Builder, as it requires much, and click on the next.

selcting desired package to setup postgresql in windows

Step - 5:

Select the directory for the database for data storage or you can keep the default folder also, click on the next.

clicking on next button after selecting package and folder to setup postgresql in windows

Step - 6:

Enter the password you want for the PostgreSQL user account, but you need to remember this password as it requires later to log in to the database server of PostgreSQL, re-type the password again, and then click on the next.

setting password for database superuser in windows

Step - 7:

Enter the port number on which the PostgreSQL server will listen, the 5432 post is used by PostgreSQL by default. It must be ensured that the entered port number is free, which means that the port number is not used by any other application.

selecting default port for postgresql in windows

Step - 8:

Now choose the locale. The current operating system locale is used by PostgreSQL by default, then click on the next.

choosing default locale for setup of postgresql in windows

Step - 9:

Check all the installation details displayed on the screen. If every information looks right, then click on the next, otherwise go back if any detail is not correct.

some settings that is used for installation of postgresql in windows

Step - 10:

Now click on the next for the installation of Postgresql in your system.

clicking on next button to finally start installation of postgresql in windows

Step - 11:

Installation takes some time

The installation may take a few minutes to complete.

installing postgresql in windows after setting up requirements

Step - 12:

After completion of installation, click on the next.

completing the postgresql setup wizard in windows

Verify the Installation

Follow the steps given below to verify the installation of PostgreSQL by the psql program.

Step - 1:

Open the psql. A psql command line will be displayed on the screen.

opening sql shell or psql to verify installation on windows

Step - 2:

Enter all the asked details like server, database, port, username, and password. You can simply press enter to accept the default. The password created at the Postgresql installation is required to be entered here.

entering all the details to open psql in windows

Step - 3:

Write the SELECT version(); and press enter and the output as given below is displayed, which means PostgreSQL is successfully installed in your system.

output of SELECT version program on windows

How to Install PostgreSQL Linux(Ubuntu)?

Follow the steps given below to install PostgreSQL on Ubuntu:

Step - 1:

Go to the PostgreSQL download for Ubuntu page.

downloading postgresql from postgresql for ubuntu page

Step - 2:

A script will be there for Postgresql installation on Ubuntu. You need to copy those commands one by one and execute them. copying script and executing one by one to install postgresql on ubuntu

Step - 3:

First, execute the command given below for the file repository configuration creation.

executing commond for file repository configuration creation

Step - 4:

Write the command given below for importing the signing key of the repository. command for importing the signing key for repository

Step - 5:

Updating the list of packages. updating the list package to install postgresql on ubuntu

Step - 6:

Write the below-given command for installation of PostgreSQL's recent version.

You can also write any particular version of Postgresql for installation, for that, you need to write postgresql-version in place of postgresql. For instance, you can write the below-given command for installing version 12 of Postgresql.

writing the command for installing latest version of postgresql on ubuntu

Now after some time PostgreSQL will be downloaded and installed in your system.

Verifying the Installation on Ubuntu

Run the command psql --version to verify whether postgresql was successfully installed or not. If PostgreSQL is installed successfully then the below output will be displayed.

running psql --version command to verify installation of postgresql on ubuntu

How to Install PostgreSQL Mac?

Downloading the PostgreSQL for Mac

Follow the steps given below for downloading the PostgreSQL installer on macOS:

Step - 1:

Go to the PostgreSQL installer download page

Step - 2:

Now download the PostgreSQL available for macOS.

Installing PostgreSQL for Mac

Follow the steps given below for PostgreSQL installation on macOS:

Step - 1:

Double-click the installer file for the launch setup wizard.

welcome page of postgresql setup wizard on mac

Step - 2:

Now select the folder for installation, you can specify any custom path or you can keep the folder by default selected by Postgresql, then click on the next.

selecting the folder for installation of postgresql on mac

Step - 3:

Select from the list of software components that you desire to install in your system, and click on the next.

selecting desired component from the list of software components to install postgresql on mac

Step - 4:

Select the directory where you want to store the data of the PostgreSQL and click on the next.

selecting the directory to store the data of the PostgreSQL on mac

Step - 5:

Enter the password you want for the PostgreSQL user account, but you need to remember this password as it requires later to log in to the database server of PostgreSQL, re-type the password again, and then click on the next.

setting the password for authentication of user on postgresql on mac

Step - 6:

Enter the port number on which the PostgreSQL server will listen, the 5432 post is used by PostgreSQL by default.

entering the default port number 5432 on which the PostgreSQL server will listen

Step - 7:

Now choose the locale. The current operating system locale is used by PostgreSQL by default, click on the next

choosing the default locale for postgresql on mac

Step - 8:

Check all the installation details displayed on the screen. If every piece of information looks right, then click on the next.

checking all the installation details for postgresql on mac

Step - 9:

Click on the next, after that PostgreSQL database server installation will start on your system.

clicking on next to start the installation on system

Step - 10:

Installation takes some time.

installing postgresql on your computer

Step - 11:

When the installation is complete click on the finish.

clicking on finish button to complete installation of psql on mac

Now Postgresql is successfully installed in your system.

Verifying the Installation

Launch the pgAdmin to verify whether the PostgreSQl is successfully installed or not.

launching pgadmin to verify the psql on mac

Conclusion