---
title: Install the pgai extension from source | Tiger Data Docs
description: Install the pgai extension from source on macOS and Linux.
---

# Install the pgai extension from source

Windows users

For Windows users, we recommend using the [pgai Docker image](/reference/pgai/extension/install/docker/index.md) to run the pgai extension. These instructions have only been tested on macOS and Linux.

To install pgai from source on a PostgreSQL server:

1. **Install the prerequisite software system-wide**

   - **PostgreSQL**: Version 16 or newer is required.

   - **Python3**: if running `python3 --version` in Terminal returns `command not found`, download and install the latest version of [Python3](https://www.python.org/downloads/).

   - **Pip**: if running `pip --version` in Terminal returns `command not found`, install it with one of the pip [supported methods](https://pip.pypa.io/en/stable/installation/#supported-methods).

   - **PL/Python**: follow [How to install PostgreSQL 16 with plpython3u on macOS, Ubuntu, Debian, CentOS, or Docker](https://github.com/postgres-ai/postgres-howtos/blob/main/0047_how_to_install_postgres_16_with_plpython3u.md).

     *macOS*: the standard PostgreSQL brew in Homebrew does not include the `plpython3` extension. These instructions show how to install from an alternate tap.

     - **[Postgresql plugin](https://github.com/smashedtoatoms/asdf-postgres) for the [asdf](https://github.com/asdf-vm/asdf) version manager**: set the `--with-python` option when installing PostgreSQL:

       Terminal window

       ```
       POSTGRES_EXTRA_CONFIGURE_OPTIONS=--with-python asdf install postgres 16.3
       ```

   - **pgvector**: follow the [install instructions](https://github.com/pgvector/pgvector?tab=readme-ov-file#installation) from the official repository. This extension is automatically added to your PostgreSQL database when you install the pgai extension.

2. Clone the pgai repo at the latest tagged release:

   Terminal window

   ```
   git clone https://github.com/timescale/pgai.git --branch extension-0.8.0
   cd pgai
   ```

3. Install the `pgai` PostgreSQL extension:

   Terminal window

   ```
   sudo just ext install
   ```

   Write access required

   The install requires write access to system-owned paths to create the following files:

   - pgai’s Python dependencies (in `/usr/local/lib/pgai`)
   - pgai’s extension files (`ai.control` and `ai--*.sql`) (in PostgreSQL’ extension directory, typically `/usr/share/postgresql/<pg version>/extension`, but configurable. Use `pg_config --sharedir` to determine this path.) If you would prefer to not run the install command using `sudo`, it must be run as a user with write access to the above paths.

   We use [just](https://github.com/casey/just) to run project commands. If you don’t have just you can install the extension with:

   Terminal window

   ```
   sudo projects/extension/build.py install
   ```

4. Connect to your database with a postgres client like [psql v16](/integrate/query-administration/psql/index.md) or [PopSQL](https://docs.timescale.com/use-timescale/latest/popsql/).

   Terminal window

   ```
   psql -d "postgres://<username>:<password>@<host>:<port>/<database-name>"
   ```

5. Create the pgai extension:

   ```
   CREATE EXTENSION IF NOT EXISTS ai CASCADE;
   ```

   The `CASCADE` automatically installs `pgvector` and `plpython3u` extensions.
