> ## Documentation Index
> Fetch the complete documentation index at: https://www.pgschema.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Installation

**Supported Operating Systems**

<Note>
  Windows is not supported. Please use WSL (Windows Subsystem for Linux) or a Linux VM.
</Note>

* Linux (AMD64, ARM64)
* macOS (Apple Silicon, Intel)

## macOS

<Tabs>
  <Tab title="Homebrew (Recommended)">
    Install pgschema using Homebrew:

    ```bash theme={null}
    # Install pgschema
    brew tap pgplex/pgschema
    brew install pgschema

    # Verify installation
    pgschema --help
    ```

    To update to the latest version:

    ```bash theme={null}
    brew upgrade pgschema
    ```
  </Tab>

  <Tab title="Pre-built Binary">
    Download and install the pre-built binary for macOS.

    <Note>
      Replace `v1.0.0` with the [latest release version](https://github.com/pgplex/pgschema/releases).
    </Note>

    ```bash theme={null}
    # Download the binary
    curl -L https://github.com/pgplex/pgschema/releases/download/v1.0.0/pgschema-1.0.0-darwin-arm64 -o pgschema

    # Make it executable
    chmod +x pgschema

    # Move to PATH
    sudo mv pgschema /usr/local/bin/

    # Verify installation
    pgschema --help
    ```
  </Tab>
</Tabs>

## Debian/Ubuntu (DEB)

Install pgschema using the DEB package on Debian, Ubuntu, or other Debian-based distributions.

<Note>
  Replace `v1.0.0` and `1.0.0` with the [latest release version](https://github.com/pgplex/pgschema/releases).
</Note>

<Tabs>
  <Tab title="AMD64">
    ```bash theme={null}
    # Download the DEB package
    curl -LO https://github.com/pgplex/pgschema/releases/download/v1.0.0/pgschema_1.0.0_amd64.deb

    # Install the package
    sudo dpkg -i pgschema_1.0.0_amd64.deb

    # Verify installation
    pgschema --help
    ```
  </Tab>

  <Tab title="ARM64">
    ```bash theme={null}
    # Download the DEB package
    curl -LO https://github.com/pgplex/pgschema/releases/download/v1.0.0/pgschema_1.0.0_arm64.deb

    # Install the package
    sudo dpkg -i pgschema_1.0.0_arm64.deb

    # Verify installation
    pgschema --help
    ```
  </Tab>
</Tabs>

## RedHat/Fedora (RPM)

Install pgschema using the RPM package on RedHat, Fedora, CentOS, or other RPM-based distributions.

<Note>
  Replace `v1.0.0` and `1.0.0` with the [latest release version](https://github.com/pgplex/pgschema/releases).
</Note>

<Tabs>
  <Tab title="AMD64">
    ```bash theme={null}
    # Download the RPM package
    curl -LO https://github.com/pgplex/pgschema/releases/download/v1.0.0/pgschema-1.0.0-1.x86_64.rpm

    # Install the package
    sudo rpm -i pgschema-1.0.0-1.x86_64.rpm

    # Verify installation
    pgschema --help
    ```
  </Tab>

  <Tab title="ARM64">
    ```bash theme={null}
    # Download the RPM package
    curl -LO https://github.com/pgplex/pgschema/releases/download/v1.0.0/pgschema-1.0.0-1.aarch64.rpm

    # Install the package
    sudo rpm -i pgschema-1.0.0-1.aarch64.rpm

    # Verify installation
    pgschema --help
    ```
  </Tab>
</Tabs>

## Pre-built Binaries (Linux)

For Linux systems without package manager support, download pre-built binaries from the [GitHub releases page](https://github.com/pgplex/pgschema/releases).

<Note>
  Replace `v1.0.0` with the [latest release version](https://github.com/pgplex/pgschema/releases).
</Note>

<Tabs>
  <Tab title="Linux AMD64">
    ```bash theme={null}
    # Download the binary
    curl -L https://github.com/pgplex/pgschema/releases/download/v1.0.0/pgschema-linux-amd64 -o pgschema

    # Make it executable
    chmod +x pgschema

    # Move to PATH
    sudo mv pgschema /usr/local/bin/

    # Verify installation
    pgschema --help
    ```
  </Tab>

  <Tab title="Linux ARM64">
    ```bash theme={null}
    # Download the binary
    curl -L https://github.com/pgplex/pgschema/releases/download/v1.0.0/pgschema-linux-arm64 -o pgschema

    # Make it executable
    chmod +x pgschema

    # Move to PATH
    sudo mv pgschema /usr/local/bin/

    # Verify installation
    pgschema --help
    ```
  </Tab>
</Tabs>

## Docker

Run pgschema using Docker without installing it locally:

```bash theme={null}
# Pull the latest image
docker pull pgplex/pgschema:latest

# Run pgschema commands
docker run --rm pgplex/pgschema:latest --help
```

```bash theme={null}
# Dump a localhost database (requires --network host)
docker run --rm --network host \
  -e PGPASSWORD=mypassword \
  pgplex/pgschema:latest dump \
  --host localhost \
  --port 5432 \
  --db mydb \
  --schema public \
  --user myuser > schema.sql
```

```bash theme={null}
# Plan migration and save to plan.json on host
docker run --rm --network host \
  -v "$(pwd):/workspace" \
  -e PGPASSWORD=mypassword \
  pgplex/pgschema:latest plan \
  --host localhost \
  --port 5432 \
  --db mydb \
  --schema public \
  --user myuser \
  --file /workspace/schema.sql \
  --output-json /workspace/plan.json
```

```bash theme={null}
# Apply changes using the saved plan.json
docker run --rm --network host \
  -v "$(pwd):/workspace" \
  -e PGPASSWORD=mypassword \
  pgplex/pgschema:latest apply \
  --host localhost \
  --port 5432 \
  --db mydb \
  --schema public \
  --user myuser \
  --plan /workspace/plan.json
```

<Note>
  **Important Docker Usage Notes:**

  * Use `--network host` when connecting to databases on localhost/127.0.0.1
  * Mount volumes with `-v "$(pwd):/workspace"` to access local schema files
  * Files inside the container should be referenced with `/workspace/` prefix
</Note>

## Go Install

If you have Go 1.24.0 or later installed, you can install pgschema directly:

```bash theme={null}
go install github.com/pgplex/pgschema@latest
```

This will install the latest version of pgschema to your `$GOPATH/bin` directory.

After installation, verify that pgschema is working correctly:

```bash theme={null}
# View help and check version
pgschema --help
```

## Build from Source

Clone the repository and build from source:

```bash theme={null}
# Clone the repository
git clone https://github.com/pgplex/pgschema.git
cd pgschema

# Build the binary
go build -v -o pgschema .

# Optional: Install to system
sudo mv pgschema /usr/local/bin/
```

<Note>Building from source requires Go 1.24.0 or later.</Note>
