PostgreSQL installation on Linux step by step

In this tutorial, we will learn how to install PostgreSQL on Linux. We will be demonstrating the installation of PostgreSQL on Ubuntu which is a Debian distro. By the end of this tutorial, you will have complete knowledge of PostgreSQL installation on Linux step by step and the below things:

  • How to Install PostgreSQL On Linux (Ubuntu)
  • Install PostgreSQL on Windows step by step
  • Install PostgreSQL on Macintosh (Mac)

PostgreSQL installation on Linux (Ubuntu or Debian distribution)

How to install postgresql in linux step by step? PostgreSQL can be installed on Ubuntu in 3 easy steps but before proceeding with the steps please make sure that you are either a root user or sudeor.

  • Open Terminal and paste the below code. Use ctrl+shift+v to paste in the terminal.
  • This command is to create a file repository configuration in your machine.
  • Once you have hit enter after providing the password new file ‘pgdg.list’ will be created at this location etc/apt/sources.list.d/
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
PosgreSQL installation on Linux
postgresql installation on linux
  • The next step in the process is importing the repository signing key. Paste the below code in the terminal and hit enter. If it returns OK, proceed to the next step otherwise troubleshoot the process.
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
PostgreSQL installation on Linux
postgresql installation on linux step by step
  • The third step is very common among regular Linux users, You need to update the repository. To update the repository follow the below code.
sudo apt update 
install postgresql in linux
install postgresql in linux
  • The final step is installing the latest version of PostgreSQL. In case you want to install any other version then simply provide the version number separated by a hyphen(-).
sudo apt-get -y install postgresql
PosgreSQL installation on Linux Steps
how to install postgresql in linux step by step
  • Once you have successfully installed the PostgreSQL now it’s time to run it. Use the below command to start PostgreSQL.
sudo -u postgres psql postgres
install PostgreSQL Linux
install PostgreSQL Linux

Here, we saw postgresql installation on linux step by step.

Read: How to connect to PostgreSQL database

PostgreSQL installation on Linux (Red Hat family)

Red Hat family or RPM is one of the most popular community that serves Enterprise level services. Red Hat Operating System provides various administrative tools which is widely used in the organizations for monitoring security threats, automatic backup and many more.

  • CentOS and Fedora are the members of Red Hat family that serves most of the features of Red Hat operating system.
  • Please note in this tutorial we will cover
  • Latest version of Red Hat and CentOS is 8, whereas for fedora it is 34 as if now.
  • Red Hat and CentOS user
installation of RPM repository in RedHat

Install PostgreSQL on Windows 10

How to install PostgreSQL on Windows 10? Follow the below steps step to install PostgreSQL on Windows 10 Operating System.

  • Before we begin it is important that you are aware of the version (windows 7, 8,10) & architecture (32 or 64 bit) of your computer. This tutorial can be followed for both architectures.
  • If you are unaware of the architecture then you can check the system properties. (right-click on ‘This PC‘ or ‘My Computer’ and select Properties from there).
Install PostgreSQL on Windows
64-bit Operating System
  • Download the PostgreSQL this link will work for both architectures. The website automatically identifies and downloads the installer file.
Downlaod PostgreSQL for Windows 10
Preview of Executable File
  • Please note 32-bit computers will be able to download PostgreSQL version 10 or lower whereas 64-bit computers will be able to download the latest version of PostgreSQL which is currently version 13.
  • Run the installer file by clicking on it. It may prompt asking for User Account Permission, click on ‘Yes‘.
Install PostgreSQL on Windows 10
PostgreSQL-User Account Control
  • Setup PostgreSQL window will appear, click Next button.
how to Install PostgreSQL on Windows 10
PostgreSQL – Setup
  • An installation directory window will appear, change the directory to C:\Program Files\PstgreSQL\13, here 13 is the version of the PostgreSQL Click on the Next button.
  • 32-bit computers will have C:\Program Files(x86)\PstgreSQL\10 so they can select this path and click on the Next button.
postgresql installation guide for windows
PostgreSQL – Installation Directory
  • A Select Component window will appear, make sure all the check boxes are checked, click Next.
postgresql installation windows
PostgreSQL – Select Components
  • Data Directory window will appear, this means where the data will be stored, Leave it as default and click Next button.
postgresql installation on windows step by step
PostgreSQL- Select Data Directory
  • Password window will appear, here you can set the password for your PostgreSQL login and click the Next button.
postgresql installation on windows step by step
PostgreSQL – Provide Password
  • Port window will appear, the default port is 5432 click on the Next button. In case, the port is occupied then you will see an error. In that situation, either you can kill the service running on port 5432 or you can simply change the port number to something else. Please keep a note of the new Port number you will need later, click the Next button.
postgresql installation guide for windows
PostgreSQL – Select Port
  • Click the Next button for the Advanced Options window.
postgresql installation windows
PostgreSQL – Advance Options
  • Pre-installation Summary window will appear, Review and click on the Next button.
postgresql installation windows tutorial
PostgreSQL – Pre Installation Summary
  • Click the Next and Next again, the installation process will start.
postgresql install windows server 2016
PostgreSQL-Ready to Install
  • Once it is installed successfully, click on the Finish button.
postgresql install windows server 2019
PostgreSQL – Finish Installation
  • To run PostgreSQL navigate to the folder in which you have installed PostgreSQL and click on the psql Application file you will be able to run the PostgreSQL commands. Alternative to this you can also run the SQL Shell (psql).
postgresql install windows cmd
PostgreSQL- Preview of SQL Shell
  • You can either use the command line or can install third-party applications like Valentina-DB
  • With this, we have completed the installation of PostgreSQL on Windows 10.

Install PostgreSQL on Macintosh (Mac)

How to install PostgreSQL on mac? Follow the below steps, to know how to install PostgreSQL on Macintosh (Mac). There are four ways of installing PostgreSQL on Macintosh but we will be sharing the best out of these and that is by installing PostgreSQL app on Macintosh (mac).

  • Download the PostgreSQL app version 13. In case you want to download the lower version then click here.
  • Click on the downloaded dmg file to open it. Once open drag the Postgres icon to the Applications folder.
  • You will be able to see Postgres successfully installed on your Macintosh (Mac). Click on the Postgres Icon. The system will verify the installation and then it will give a prompt “Postgres” is an application downloaded from the internet. Are you sure you want to open it? Click on the Open button.
  • The screen will appear with the message “Empty data directory”, click on the initialize button.
  • It will take some time and the status “Running” will appear with the three default databases.
  • the final step in the process is to set up the environment $PATH paste the below code on the terminal.
sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
  • Restart the terminal and type, psql -U postgres here Postgres in the database name. Now you can start typing the PostgreSQL commands.
  • So with this, we have learned, how to install PostgreSQL on Macintosh (Mac) using the Postgres app.

You may like:

In this tutorial, we have learned how to install PostgreSQL on Linux, Windows, and Macintosh operating systems. The latest version of Postgres to date is 13 and the default port is 5432 for all the operating systems.

  • Postgresql installation on linux step by step
  • Install PostgreSQL On Linux (Ubuntu)
  • How to Install PostgreSQL on Windows step by step
  • Install PostgreSQL on Macintosh (Mac)

Leave a Comment