Running Local LLMs for Coding with Ollama
Run open-weight coding models locally with Ollama: hardware needs, quantization, pulling models, the local API, editor integration and when local makes sense...
Published November 27, 2026
Cloud AI assistants are powerful, but some code cannot leave your machine, some developers work offline, and some teams want predictable costs. Open-weight models running locally answer those needs. Ollama makes it about as easy as installing a package: one command downloads a model and exposes a local API your editor and scripts can use.
The concept
Ollama wraps the llama.cpp inference engine with a simple CLI, a model library and an HTTP API on localhost:11434. Models are distributed in quantized formats (GGUF), which store weights in 4 to 8 bits instead of 16, shrinking memory requirements several times with modest quality loss. A 7-8 billion parameter model at 4-bit fits in roughly 5-6 GB of memory and runs well on a recent laptop GPU or Apple Silicon.
Local models are smaller than frontier cloud models, so set expectations accordingly. They are very good for completion, explaining code, writing small functions, commit messages and private document Q&A. For large multi-file refactors and complex reasoning, the largest cloud models still lead. Many developers use both: local for private or quick tasks, cloud for hard ones.
Sizing hardware
| Model size | Memory (4-bit, approx.) | Typical hardware | Good for |
|---|---|---|---|
| 1-4B | 1-3 GB | Any modern laptop | Fast autocomplete, simple edits |
| 7-9B | 5-7 GB | 8 GB+ GPU or 16 GB Apple Silicon | General coding chat, completion |
| 13-16B | 9-12 GB | 12-16 GB GPU or 32 GB unified memory | Better reasoning |
| 30-34B | 18-22 GB | 24 GB GPU or 48 GB unified memory | Strong local coding assistant |
| 70B+ | 40 GB+ | Multiple GPUs or 64-128 GB unified memory | Near cloud quality on some tasks |
Rules of thumb; actual needs depend on context length and quantization.
How the pieces connect
Getting started
Quantization trade-off
Practical examples
Call the local API
Ollama exposes its own API and an OpenAI-compatible endpoint.
curl http://localhost:11434/api/generate -d '{
"model": "qwen2.5-coder:7b",
"prompt": "Explain what this regex matches: ^\\d{3}-\\d{4}$",
"stream": false
}'
# OpenAI-compatible
curl http://localhost:11434/v1/chat/completions -H 'content-type: application/json' \
-d '{"model":"qwen2.5-coder:7b","messages":[{"role":"user","content":"hi"}]}'Use it from Python with the OpenAI SDK
Point the base URL at Ollama; the API key is ignored.
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
reply = client.chat.completions.create(
model="qwen2.5-coder:7b",
messages=[{"role": "user", "content": "Write a pytest for a function add(a, b)."}],
)
print(reply.choices[0].message.content)Customise a model with a Modelfile
Set a system prompt and context length once.
FROM qwen2.5-coder:7b
PARAMETER num_ctx 16384
PARAMETER temperature 0.2
SYSTEM "You are a senior Laravel developer. Answer concisely with code."
# ollama create laravel-helper -f Modelfile && ollama run laravel-helperCommon mistakes
- Choosing a model too large for available memory, causing swapping and painfully slow output.
- Expecting a small local model to match the largest cloud models on complex refactors.
- Exposing the Ollama port to the network without authentication.
- Using the default small context window and wondering why the model forgets earlier parts of a long file.
- Ignoring model licenses; open-weight does not always mean unrestricted commercial use.
Key takeaways
- Ollama makes local, private LLMs a one-command install with a local API.
- Quantization (4-5 bit) lets 7-34B models run on developer hardware.
- Local models suit private, offline and quick tasks; cloud models lead on hard reasoning.
- Keep the API on localhost and check model licenses.
FAQ
Do I need a GPU?
No, but it helps a lot. Apple Silicon unified memory works very well; CPU-only inference works for small models but is slower.
Which local model is best for code?
It changes frequently. Look at current code-specialised open-weight families and try two or three sizes on your own tasks.
Can multiple developers share one local model server?
Yes. Run Ollama or a server like vLLM on a shared GPU machine inside your network, behind authentication.