Install the psql command-line tool

To connect to your AlloyDB for PostgreSQL instance from the command line, you can install the psql client tool on macOS, Linux, or Windows. The psql command-line tool is a terminal-based frontend to PostgreSQL that is required by the gcloud beta alloydb connect command and is also used for direct database connections.

macOS

To install psql on macOS, we recommend using Homebrew:

  1. Install the postgresql package:

    brew install postgresql
    
  2. Add psql to your PATH by following the instructions provided in the terminal output after the installation completes. For example:

    echo 'export PATH="/opt/homebrew/opt/postgresql@18/bin:$PATH"' >> ~/.zshrc
    source ~/.zshrc
    

Linux (Debian or Ubuntu)

Use your distribution's package manager to install the PostgreSQL client:

sudo apt-get update
sudo apt-get install postgresql-client

For other distributions, see the official PostgreSQL download page.

Windows

To install psql on Windows, you can use the interactive installer.

Installer

  1. Download the PostgreSQL Interactive Installer for Windows from the PostgreSQL downloads page.
  2. Run the installer. When prompted to select components, you can install only Command Line Tools.
  3. Add the bin directory of your PostgreSQL installation (for example, C:\Program Files\PostgreSQL\18\bin) to your system PATH environment variable.

Verify the installation

After installation, verify that psql is in your PATH and is working correctly:

psql --version

If installed correctly, the output shows the version of the psql client tool.

What's next