Installing PostgreSQL on macOS


Postgres is one of the most advanced SQL databases. It provides features from user-defined types to table inheritance and sophisticated locking. There’s also foreign key referential integrity, nested transactions, and features you won’t find in other SQL databases.

Postgres is ACID (atomicity, consistency, isolation, durability) compliant. You’ll find the Postgres database helpful when building applications that need scalability and data safety.

Use a Package Manager or Download the Installer

You can install Postgres on your macOS device using many sources and methods.

If you use a package manager, you can check the Postgres installation instructions on its website.

Here’s the command for installing Postgres versions 13 and 14 with the Homebrew package manager:

brew install [email protected]  
brew install [email protected]

Since Homebrew works on Linux and macOS, the command is compatible with both operating systems.

If you don’t use a package manager, you can install Postgres via an Apple Disk Image (.dmg) file. You should download the image of the Postgres version you need and install the app on your machine.

Set Up the Postgres App on macOS

After you’ve installed Postgres, launch the app. You’ll get a UI with the server settings option and preinstalled databases, as shown below. Launching the app automatically runs Postgres; by default, Postgres runs on port 5432 on macOS.

You can use the Server Settings button to change the server and ports for your database. You’ll also get an overview of the installation, configuration, log, and data directories you can access from the interface.

You can open your database instance (a default one is created with your username) to access the Postgres command line interface.

Add Postgres to Your PATH

Once you’ve installed the Postgres app, you’ll need to add its path to your $PATH environment variable to run it outside the app’s own terminal.

Open your Applications folder in Finder, Control-click on the Postgres app, and select Show Package Contents.

On selecting the “Show Package Contents” option, you’ll be able to view the contents of the Postgres app.

Open the Contents folder, then the Versions folder, then select your version folder (in this case, 14).

Ctrl-click the bin folder and hold the options button on your keyboard, then select Copy bin as Pathname to add the path to your clipboard.

You’ll need to edit your terminal’s zsh source zshrc file to add the Path export to the Postgres app.

Open your terminal app, and run this command to edit the zshrc file:

vim ~/.zshrc

The command will open the zshrc file in a Vim editor that you can use to edit the file.

If you’re not comfortable using vim, you can use any other text editor. The .zshrc file is in your home directory, and you’ll need to be viewing hidden files to access it.

Add an export statement and specify the path of your Postgres app. For example:

export PATH=$PATH:/Applications/

Save the source file, exit the Vim editor, restart your terminal app, and run the psql command from your newly opened terminal:


When you run the psql command you should see a command interface that connects you to your Postgres database instance. This is similar to opening Postgres via the app:

You can now use Postgres from a command line, without launching the Postgres app. This process works for most versions of Postgres, and you can use this process on Silicon or Intel chips.

Postgres Is a Multi-Platform Database

The Postgres database is reputable for its features and support across different ecosystems. You can use it on a variety of software development stacks, cloud computing services, and operating systems.

You can get started with Postgres quickly since it supports SQL, an English-like syntax that databases like MySQL and SQLite also use.

Source link

Share it with your friends

Crowded Hell

Crowded Hell

Leave a Reply

Your email address will not be published.