Book

 · 17天 ago

Aider 安装与配置步骤

Aider 安装与配置步骤(针对本地 Ollama + 30B 模型,如 Qwen3-Coder-30B 或 Qwen2.5-Coder-32B,适用于你的中型 Ruby on Rails 项目,基于 2026 年 1 月最新官方文档):

1. 先决条件

  • Python 3.9–3.13(推荐 3.12)
  • Git 已安装
  • Ollama 已安装并运行(从 https://ollama.com 下载安装)
  • 你的 Rails 项目在 Git 仓库中(Aider 依赖 Git)

2. 安装 Ollama(如果还没装)

  • Windows/Mac/Linux:官网下载安装器运行。
  • Linux 示例(命令行):
    curl -fsSL https://ollama.com/install.sh | sh
  • 启动 Ollama 服务(后台运行):
    ollama serve

3. 下载并准备 30B 模型(推荐 Qwen Coder 系列)

  • 拉取模型(Qwen3-Coder-30B 示例,需先确认 Ollama 库中有此 tag):
    ollama pull qwen3-coder:30b
    ollama pull qwen2.5-coder:32b-instruct
  • 重要:Ollama 默认上下文 2k token,太小!启动服务时增大(推荐 8k–32k,根据你的 128GB 内存):
    OLLAMA_CONTEXT_LENGTH=16384 ollama serve   # 或更高如 32768
    (新终端运行,或用 Modelfile 创建自定义模型:FROM qwen3-coder:30b \n PARAMETER num_ctx 16384,然后 ollama create myqwen -f Modelfile)

4. 安装 Aider

  • 推荐一键安装(Mac/Linux):
    curl -LsSf https://aider.chat/install.sh | sh
  • Windows PowerShell:
    powershell -ExecutionPolicy ByPass -c "irm https://aider.chat/install.ps1 | iex"
  • 或用 pip(虚拟环境更好):
    python -m pip install -U aider-chat

5. 配置 Aider 使用 Ollama(本地无 API Key)

  • 设置环境变量(Mac/Linux):
    export OLLAMA_API_BASE=http://127.0.0.1:11434
  • Windows:
    setx OLLAMA_API_BASE http://127.0.0.1:11434
    (运行后重启终端)
  • 推荐:用 ollama_chat/ 前缀(兼容性更好):
    aider --model ollama_chat/qwen3-coder:30b

6. 在你的 Rails 项目中使用

  • 进入项目目录(必须是 Git repo):
    cd /path/to/your/rails-project
  • 启动 Aider(示例):
    aider --model ollama_chat/qwen3-coder:30b
    或指定上下文/其他选项(推荐中型项目):
    aider --model ollama_chat/qwen3-coder:30b --4o --map-tokens 2048
    (--4o 用 Claude 风格提示,--map-tokens 控制 repo map 大小)

7. 常用提示 & Rails 项目最佳实践

  • 首次启动后,Aider 会自动建 repo map(代码库地图),对中型 Rails 很有帮助。
  • 命令示例:
    • 添加新功能:Add a new User model with devise authentication
    • 修复 bug:Fix the bug in app/controllers/posts_controller.rb where create action fails on validation
    • 重构:Refactor the User model to follow Fat Model Skinny Controller, move logic from controller
  • 提示技巧:用自然语言描述任务,Aider 会自动编辑文件、git commit(可 /undo)。
  • 如果上下文丢了:增大 OLLAMA_CONTEXT_LENGTH 或用 --no-stream 测试。

一句话总结:安装 Ollama → 拉模型 → 增大上下文 → 一键装 Aider → aider --model ollama_chat/qwen3-coder:30b 启动,即可在你的 Rails 项目里像 Claude Code 一样本地 pair programming,无限用、隐私满分!

遇到问题?运行 aider --help/help 在 Aider 里问。需要我帮你写 Modelfile 或具体 Rails 提示模板吗?

Download Pickful App

Better experience on mobile

iOS QR

iOS

Android QR

Android

APK QR

APK