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](https://www.postgresql.org/download/) that is required by the
[`gcloud beta alloydb connect`](https://docs.cloud.google.com/sdk/gcloud/reference/beta/alloydb/connect.md.txt)
command and is also used for direct database connections.

## macOS

To install `psql` on macOS, we recommend using [Homebrew](https://brew.sh/):

1. Install the `postgresql` package:

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

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

   > [!NOTE]
   > **Note:** The path might differ depending on your hardware architecture (Intel or Apple Silicon).

## Linux (Debian or Ubuntu)

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

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

For other distributions, see the [official PostgreSQL download
page](https://www.postgresql.org/download/).

## 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](https://www.postgresql.org/download/windows/).
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:

```bash
psql --version
```

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

## What's next

- [Connect using gcloud CLI](https://docs.cloud.google.com/alloydb/docs/connect-gcloud.md.txt).
- [Connect from Compute Engine](https://docs.cloud.google.com/alloydb/docs/connect-psql.md.txt).