psql command not found - Mac

Page content

How to Install psql Command on Mac

If you are trying to use the psql command on your Mac and find that it is not available, it is because psql is a command-line interface for interacting with PostgreSQL databases, and it is not included by default on macOS.

Installation Steps

To install the psql command on your Mac, follow these steps:

  1. Install PostgreSQL: The psql command is part of the PostgreSQL database system. You can download and install PostgreSQL for macOS from the official website: PostgreSQL Downloads.

  2. Add psql to PATH: After installing PostgreSQL, you will need to add the PostgreSQL bin directory to your PATH. This can be done by adding the following line to your .bash_profile or .zshrc file:

    export PATH=$PATH:/Library/PostgreSQL/{version}/bin
    

    Replace {version} with the actual version number of PostgreSQL you installed.

  3. Restart Terminal: After making the PATH changes, restart your terminal or run source ~/.bash_profile or source ~/.zshrc to apply the changes.

  4. Verify Installation: You can now test if the psql command is available by running:

    psql --version
    

Compatibility Note

If any of the commands or steps mentioned above are not compatible with your macOS version or setup, you can explore alternative methods such as using Homebrew to install PostgreSQL or adjusting the PATH based on your installation directory.

Conclusion

By following these steps, you should now have the psql command available on your Mac, allowing you to interact with PostgreSQL databases from the command line.