How To Install PostgreSQL On Mac

Introduction

 
In this article, you will learn how to download and install PostgreSQL on a Mac.
 
Let's begin.
 
There are many ways to download and install PostgreSQL on Mac but in this article, we will see 2 main ways to download and install PostgreSQL.
 
Let's look into the first one.
 

Using Postgresapp

 
So for getting PostgreSQL on your Mac go to the link below and download it and follow the steps.
 
 
After opening the link you will see the option for downloading PostgreSQL. Select the latest stable version.
 
For Mac users, the way you connect to the database is simply by opening the elephant icon on the bar and making sure that your database is running, and then clicking on “Open Postgres”.
 
 
Right after that, you will see that you have 3 databases by default.
 
 
 
Just click on any of the default databases and you will see that your terminal will open.
 
As you can see in the above image you are in a database mode right now.
 
 
Now open a new shell and type “psql”.
 
Now you will see that the “command not found”.
 
 
This error occurs because we need to add to the path.
 
So to do so we are simply going to add to the path.
 
This assumes that everyone is using iTerm as well as “Oh My ZSH”
 
Now close the terminal and open iTerm.
 
And type the command given below
 
Cd ~
ls -a
 
 
You can see the file in there but the one which we need is “.zshrc”.
 
Now again give a command: “vi .zplshrc” 
 
 
 
Now you need to add export in the “path”.
 
Copy the path of the database from the Postgres default database.
 
As shown in the image given below.
 
 
Now paste the path you copied for the default database.
 
And remove the psql from the path.
 
 
Now to come out from this file you just need to press ESC and then:wq
 
There you go you came out of the file and also added the path.
 
This was the first way to install PostgreSQL on Mac.
 
Let's look at the second option.
 

Using interactive installer by EDB

 
For using interactive installer by EBD you need to go to the link given below.
 
After opening the link you will see that MacOs icon on your screen.
 
Click on MacOs.
 
 
Now you will see multiple options for downloading and installing PostgreSQL.
 
Click on the first option on your screen. which is Download the installer by EDB.
 
 
Now you will see multiple versions of PostgreSQL of MacOs as well as other operating systems.
 
Look for the stable version of the installer and click on that.
 
 
After downloading the installer click on the downloaded file and wait for the installer to open.
 
 
Give the required permission asked for installation. And click on open.
 
 
After clicking on open wait for till the installer prepares the file to be installed.
 
  
  
 
Click on Next and move to the next step.
 
 
Select the location where you want to make your directory for PostgreSQL.
 
You can keep it at the default location if you don't want to specify the location.
 
After selecting click on next.
 
 
In this step, you need to select the component which you required for your project.
 
Keep this also as default, if you don't want to specify.
 
After selecting click on next.
 
 
In this step select the location where the Data Directory will be created.
 
You can keep this as the default.
 
After selecting the location click on next.
 
 
Now you need to create a password for yourself.
 
After creating the password click on next.
 
 
Select the port which will be used by PostgreSQL.
 
You can keep this also as default. If you don't want to specifically change the port number.
 
After selecting the port click on next.
 
 
If you want to specify the location which will be used by the new database cluster.
 
After selecting click on next.
 
 
Click on next.
 
 
This step says that the setup is ready to install PostgreSQL on your computer.
 
Click on next.
 
 
And here we go the installation of PostgreSQL started, it will take few minutes.
 
 
After this, you have successfully installed PostgreSQL on your computer.
 
Click on finish, and you are ready to go.
 

Conclusion

 
In this article, you learned how to install PostgreSQL on macOS using 2 different ways.
 
In the upcoming article, you will learn more about PostgreSQL and how to use all the tools which are provided by PostgreSQL to manage a database.


Similar Articles