It also allows you to create batch commands, load them from a file, and then execute them on the server.
Needless to say, it is a great tool when working with PostgreSQL from the terminal.
This tutorial will discuss how to fix the “psql command not found” error on Windows, macOS, and Linux.
Installing PostgreSQL. – Windows
The first step is to ensure that you have PostgreSQL installed on your system.
On Windows: Start by opening your browser and navigating to the resource below:
Select the version for your Windows system and start the download.
Launch the installer package once the download is complete and follow along with the setup wizard.
Under the “Select Components” Section, ensure to select “Command Line Tools.”
Set your Data Directory, Password for your PostgreSQL cluster, and the running port.
Click Finish to finish the installation process.
Installing PostgreSQL – macOS
On macOS, open the browser and navigate to the link below:
Download the installer version for OSX.
Once the download is complete, mount the dmg file and launch the PostgreSQL app.
Follow along with the Wizard and set the appropriate options as you see fit.
Under “Select Components,” ensure to include “Command Line Tools.”.
And with that, you should have PostgreSQL installed on your system.
Installing PostgreSQL – Linux
To install PostgreSQL on Linux, navigate to the resource below, select your Linux version, and copy the installer script.
Paste the command in your terminal. It should install PostgreSQL.
Fix : Adding PATH for PostgreSQL Tools
Once you have installed PostgreSQL on your system, you must add the PostgreSQL bin directory to your PATH variable.
On Windows, launch the command prompt and enter the command:
In our case, the path to the PostgreSQL bin directory is
If your installation is in a custom location, feel free to update it as you see fit.
If you are looking for a GUI option, open the Windows Search and enter “env.”
Select “Edit the System Environment Variables.”
Select the “Environment Variables” option in the “System Properties” window at the down-right corner.
Under the “System Variables” option, select the PATH option and click “Edit.”
Click on New and add the path to your PostgreSQL bin directory.
Click on Save to apply the changes.
Open the terminal and run the command:
The command above should return the PostgreSQL version installed on your system.
psql (PostgreSQL) 14.3
Fix: Add PostgreSQL Tools to Path – macOS
To add PostgreSQL tools to the PATH on macOS, edit your .zshrc or .bashrc file and add the following line:
Save the file and close. Apply the changes as:
Fix: Add PostgreSQL Tools to Path – Linux
If you installed PostgreSQL using the installer script in the provided instructions above, you should have the PostgreSQL tools added to the path.
However, if you don’t, add the following line to your .basrch file:
Replace the version with your installed PostgreSQL version.
Apply the changes;
In this article, we dove deep into how you can fix the “psql command not found” on Windows, Linux, and macOS.