Aider on Ubuntu 24.04: A Practical Guide to Connecting an LLM in the Terminal

    Learn how to install the open-source terminal coding assistant Aider on Ubuntu 24.04 LTS using pipx, connect it to an OpenAI-compatible LLM API (using DeepSeek as an example), and verify your configuration step by step.

    Who This Guide Is For and What You’ll Get

    If you prefer writing code in the terminal and want an assistant that can read your project files, modify code directly, and track every change, Aider is worth a try. It’s a command-line tool written in Python. Once launched, it adds the project files you specify to the conversation context, generates code changes based on your instructions, and shows the differences as patches.

    This guide is aimed at developers with basic Linux command-line experience. It covers three goals:

    1. Install Aider on Ubuntu 24.04 LTS;
    2. Connect Aider to an OpenAI-compatible LLM service;
    3. Verify the configuration and learn how to handle common errors.

    Aider does not provide model capabilities itself—it calls an external model API. So the integration only involves three pieces of information: the API endpoint (Base URL), the API key, and the model name. As long as your provider offers an OpenAI-style API, the configuration process is identical. This guide uses DeepSeek as an example; for other providers, simply swap in their corresponding values.

    Prerequisites

    First, update the system and install pipx along with basic tools. pipx installs Python CLI tools into isolated virtual environments, avoiding conflicts with system Python packages. Ubuntu 24.04 blocks pip from installing global packages into the system Python by default, so pipx is the recommended approach.

    1. sudo apt update && sudo apt upgrade -y
    2. sudo apt install -y pipx python3-venv git curl
    3. pipx ensurepath

    pipx ensurepath adds pipx’s binary directory to your PATH by modifying ~/.bashrc. After running it, close the current terminal and open a new one so the PATH change takes effect.

    Check your Python version:

    1. python3 --version

    Ubuntu 24.04 ships with Python 3.12 by default, which Aider supports. The output should look like Python 3.12.x.

    Aider works inside a Git repository and uses Git to record every change it makes. If your project isn’t using Git yet, run git init first.

    Installing Aider

    Install with pipx:

    1. pipx install aider-chat
    2. aider --version

    If a version number is printed, the installation succeeded. If you see command not found, the PATH likely hasn’t been updated yet—reopen your terminal.

    Aider has quite a few dependencies, so the first installation may take a few minutes. Once complete, the aider command will be available under ~/.local/bin.

    Connecting to an LLM Service

    Integration requires three pieces of information. Using DeepSeek as the example:

    • Base URL: https://api.deepseek.com/v1 — the root path of DeepSeek’s OpenAI-compatible API;
    • API Key: created in the provider’s platform console, a string starting with sk-;
    • Model name: deepseek-chat, the general-purpose chat model.

    4.1 Store the Key in a Dedicated File

    An API key is an account credential. Don’t append it to ~/.bashrc with something like echo 'export KEY=...' >> ~/.bashrc—that leaves the key in your shell history and loads it in every new terminal. The recommended practice is to write the key into a file readable only by you, which Aider reads on demand.

    Create the file and restrict its permissions to read/write for your user only:

    1. touch ~/.env
    2. chmod 600 ~/.env
    3. nano ~/.env

    In the editor, add the following two lines, replacing the key with your own:

    1. OPENAI_API_BASE=https://api.deepseek.com/v1
    2. OPENAI_API_KEY=sk-your-key-here

    After saving, verify the permissions are 600:

    1. stat -c '%a %n' ~/.env

    Aider automatically reads the ~/.env file in your home directory—this is its standard behavior. If you want to specify the file explicitly, add --env-file ~/.env at launch.

    This approach still carries risk: anyone who can read your home directory can obtain the key. So never place ~/.env inside any project directory, and never commit it to a Git repository. If a .env file ever appears in a project directory, add it to .gitignore.

    4.2 Set the Default Model

    Create Aider’s configuration file ~/.aider.conf.yml in your home directory and set the default model:

    1. model: openai/deepseek-chat

    The openai/ prefix tells Aider to call the model via the OpenAI-compatible protocol. The part after the prefix is the model name from the provider’s console and must match it exactly, including capitalization.

    The configuration file stores only the model name; the key stays in ~/.env. Keep the two managed separately.

    Verifying Connectivity

    Before launching Aider properly, call the API directly with curl. This step helps you determine whether a problem lies with the network, the key, or the tool itself.

    First, load the variables from ~/.env into the current shell. set -a automatically exports the variables read afterward:

    1. set -a
    2. . ~/.env
    3. set +a

    Then send