How to run an AI coding model locally
You can have a private AI coding assistant running on your own computer with a few commands (plus the model download). Here's how, with three free options.
When you use a cloud AI, everything you send it is received and handled by another company. Running a model locally keeps your prompts and code on your computer (only the model download needs the internet), and there are no usage fees. Here are three free ways to do it, and how to connect the model to your coding tools.
Before you start
- Memory: 16 GB runs small models comfortably (8 GB only the smallest), and 32 GB runs capable 20B to 30B models. See what computer you need.
- Disk space: models range from a few gigabytes to over 50 GB.
- A model: see the best open-source coding models to pick one that fits.
Option 1: Ollama (Mac, Windows, Linux)
Ollama is a free, open-source (MIT) model runner.
- Download and install it from ollama.com/download.
- Open a terminal and run a model, for example:
ollama run gemma4:e2bfor a small model, orollama run qwen3.8if you have 32 GB of memory. The first run downloads the model. - Chat with it in the terminal. Type
/byeto exit.
Useful commands: ollama pull <model> downloads without starting a chat, ollama ps shows what's loaded and whether it's running on your graphics hardware, and ollama stop <model> unloads it. Ollama also runs a local server at localhost:11434 that other tools can connect to. It also offers optional cloud models, which run on Ollama's servers rather than your computer; set OLLAMA_NO_CLOUD=1 to keep it local-only.
Tip for codingOllama recommends a context length of at least 64,000 tokens for coding tools, which needs more memory. You can set it when starting the server: OLLAMA_CONTEXT_LENGTH=64000 ollama serve
Option 2: LM Studio (Mac, Windows, Linux)
LM Studio is a free desktop app, for home and work use, with a graphical model browser. It runs models with llama.cpp on every platform, plus MLX on Apple silicon Macs. On a Mac it needs Apple silicon and macOS 14 or later, with 16 GB recommended. Install it, search for a model, download it and start chatting. It can also run a local server for other tools.
Option 3: MLX (Apple silicon Macs)
MLX is Apple's open-source machine learning framework, built for Apple silicon. Its mlx-lm package runs models from the terminal:
- Install:
pip install mlx-lm - Chat with a model:
mlx_lm.chat(it uses a small default model unless you add--model) - Or serve one for other tools:
mlx_lm.server --model mlx-community/Mistral-7B-Instruct-v0.3-4bit
Connect it to your coding tools
A chat in the terminal is a start, but the real benefit comes from using the model where you code. VS Code supports local models, and open-source assistants such as Cline and Aider work with Ollama. On a Mac, see local AI coding on a Mac for the apps and which models fit your memory.
The easiest route on a Mac: Nexus
Nexus skips most of these steps. It has a built-in MLX engine, so you download an open model inside the app and pick it in the chat; no terminal needed. If you already use Ollama, Nexus can use those models too. You get a visual workspace with a live preview, diffs and restore points, and you can switch to Claude Code by Anthropic or the Codex app by OpenAI for harder tasks (these send your code to Anthropic or OpenAI). Nexus will be a one-time purchase of $199 USD, with no Nexus subscription. Connecting third-party AI services such as Claude Code or Codex is optional and at your own expense (see Nexus pricing). It's for Apple silicon Macs with macOS 12 or later (14 or later for local models and the Codex app, 13 or later for Claude Code), and it's coming soon.
Frequently asked questions
What is the easiest way to run an AI model locally?
Ollama and LM Studio are both free and simple. Install either, download a model and start chatting. Ollama also runs a local server other coding tools can connect to.
Do I need the internet to run a local model?
Only to download the model. After that it runs without a connection.