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+vto paste in the terminal.
- This command is to create a file repository configuration in your machine.
- Once you have hit
enterafter providing the password new file ‘pgdg.list’ will be created at this location
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
- 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 -
- 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
- 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
- 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
Here, we saw postgresql installation on linux step by step.
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
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).
- Download the PostgreSQL this link will work for both architectures. The website automatically identifies and downloads the installer 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‘.
- Setup PostgreSQL window will appear, click Next button.
- 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.
- A Select Component window will appear, make sure all the check boxes are checked, click Next.
- Data Directory window will appear, this means where the data will be stored, Leave it as default and click Next button.
- Password window will appear, here you can set the password for your PostgreSQL login and click the Next button.
- 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.
- Click the Next button for the Advanced Options window.
- Pre-installation Summary window will appear, Review and click on the Next button.
- Click the Next and Next again, the installation process will start.
- Once it is installed successfully, click on the Finish button.
- 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).
- 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 postgreshere 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.
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)