AI Pair Programming in Your Terminal with Aider and Ollama

AI Pair Programming in Your Terminal with Aider and Ollama

在终端中使用 Aider 和 Ollama 进行 AI 结对编程

Want an AI coding assistant that works on YOUR codebase, respects YOUR git history, and doesn’t send your code to the cloud? Aider + Ollama gives you exactly that. Aider is an AI pair programming tool that works directly in your terminal. It sees your files, understands your git repo, and makes real edits to your code. Paired with Ollama running a local model, you get a fully private coding assistant.

想要一个能在你的代码库上工作、尊重你的 Git 历史记录,且不会将代码发送到云端的 AI 编程助手吗?Aider + Ollama 正是为你准备的。Aider 是一款直接在终端中运行的 AI 结对编程工具。它能查看你的文件、理解你的 Git 仓库,并对你的代码进行实际的编辑。配合运行本地模型的 Ollama,你将获得一个完全私密的编程助手。

Prerequisites

前置要求

  • GPU: RTX 3090 or 4090 with 16GB+ VRAM (for Qwen3 Coder 30B at Q4)

  • Software: Python 3.10+, Ollama installed

  • Time: ~10 minutes setup

  • GPU: RTX 3090 或 4090,显存 16GB 以上(用于运行 Q4 量化的 Qwen3 Coder 30B 模型)

  • 软件: Python 3.10+,已安装 Ollama

  • 时间: 约 10 分钟配置时间

Installation

安装

# Install Aider
pip install aider-chat

# Pull a capable coding model
ollama pull qwen3-coder:30b-a3b
# 安装 Aider
pip install aider-chat

# 拉取一个强大的编程模型
ollama pull qwen3-coder:30b-a3b

Configuration

配置

Set Aider to use your local Ollama model: 设置 Aider 以使用你的本地 Ollama 模型:

# For bash/zsh
export OLLAMA_CONTEXT_LENGTH=8192

# Run Aider with Ollama
aider --model ollama_chat/qwen3-coder:30b-a3b --editor

For persistent config, create .env in your project: 若需持久化配置,请在你的项目中创建 .env 文件:

OLLAMA_CONTEXT_LENGTH=8192
AIDER_MODEL=ollama_chat/qwen3-coder:30b-a3b

Usage

使用方法

# Start Aider in your project directory
cd my-project
aider --model ollama_chat/qwen3-coder:30b-a3b

# Now just describe what you want:
# "Add error handling to the API routes"
# "Refactor the database connection into a singleton"
# "Write unit tests for the user service"
# 在项目目录下启动 Aider
cd my-project
aider --model ollama_chat/qwen3-coder:30b-a3b

# 现在只需描述你的需求:
# “为 API 路由添加错误处理”
# “将数据库连接重构为单例模式”
# “为用户服务编写单元测试”

Aider reads your files, makes changes, and commits them with sensible messages. You approve each change before it’s applied. Aider 会读取你的文件、进行修改,并附带合理的提交信息进行提交。在应用每项更改之前,你都需要进行确认。

Results

性能表现

On a RTX 4090 with Qwen3 Coder 30B at Q4: ~15-20 tok/s, enough for real-time code suggestions. Qwen2.5 Coder 14B runs faster (~35 tok/s) and fits on a 12GB GPU, great for smaller projects.

在 RTX 4090 上运行 Q4 量化的 Qwen3 Coder 30B 模型:速度约为 15-20 tok/s,足以满足实时代码建议的需求。Qwen2.5 Coder 14B 运行速度更快(约 35 tok/s)且适用于 12GB 显存的 GPU,非常适合小型项目。

Why Local?

为什么要本地运行?

  • Privacy - your proprietary code never leaves your machine

  • No API costs - unlimited suggestions for $0/month

  • Works offline - code on a plane, in a cafe, anywhere

  • No rate limits - use it all day without throttling

  • 隐私性 - 你的专有代码永远不会离开你的机器

  • 无 API 费用 - 每月 0 美元即可获得无限建议

  • 离线工作 - 在飞机上、咖啡馆或任何地方都能编程

  • 无速率限制 - 全天使用,无需担心限流

Originally published on everylocalai.com 原文发布于 everylocalai.com