ollama) plus a background daemon on port 11434. You can pull and run models like Llama 3.2, Qwen 2.5, and DeepSeek-R1 entirely offline. This guide walks through the pieces most tutorials skip: how the daemon actually loads models, precise VRAM math per quantization, writing real Modelfiles, pointing the server at other machines, and fixing the errors that trip people up.
When you hear “I run LLMs locally,” what people almost always mean is Ollama. It has become the default way to run open-weight models on a laptop or workstation, and yet most guides stop at ollama run llama3.2 and call it a day. This one does not. It assumes you actually want to operate Ollama day to day — load models into the right amount of VRAM, serve them to other devices, hand-tune context and sampling, and recover when something breaks.
Everything below is organized the way real work flows: understand the moving parts, install correctly per OS, learn the CLI, tune with Modelfiles, budget your VRAM, expose the API, and diagnose failures. Along the way I flag the mistakes that are easy to make and painful to undo.
1. How Ollama Works: the daemon, the GGUF file, and why VRAM matters
Ollama is a client–server application. The installer launches a background HTTP server bound to 127.0.0.1:11434, and every command you type in the ollama CLI is just a request to that server. Keep that model in mind, because it explains a huge share of real-world confusion: “the CLI works but my app can’t connect” and “why is port 11434 open?” are all consequences of a separate server process.
| Component | What it is | Why it matters |
|---|---|---|
| Core engine | llama.cpp, compiled with the SIMD and GPU targets Ollama ships |
The actual matrix math and token generation. Upgrading Ollama upgrades the engine underneath your models. |
| Model file | GGUF, with the weights stored as sharded blobs plus a manifest | GGUF stores the exact quantized tensors. The chosen quant is your file size and quality trade-off. |
| Server daemon | A Go HTTP server hosting /api/* and the OpenAI-compatible /v1/* routes |
Loads models into memory, evicts them, and manages the context window. All API calls hit this process. |
| GPU backends | CUDA for NVIDIA, ROCm for AMD, Metal for Apple Silicon | Determines whether layers run on the GPU or spill to CPU RAM. |
The single most important number in local LLMs is bytes-per-parameter. An unquantized FP16 model uses 2 bytes per parameter, so an 8B model needs ~16 GB just for weights. The GGUF format instead ships quantized weights that use far fewer bytes:
| Quant | Rough bytes/parameter | 8B model, weights only | Typical use |
|---|---|---|---|
Q8_0 |
~1.1 | ~8.4 GB | Near-lossless; for servers/CPU where RAM is cheap. |
Q5_K_M |
~0.69 | ~5.3 GB | Highest quality when VRAM allows. |
Q4_K_M |
~0.56 | ~4.7 GB | The Ollama default and the sensible everyday choice. |
Q3_K_M |
~0.44 | ~3.5 GB | Last resort on tight VRAM; visible quality loss. |
Those sizes are weights only — almost nobody warns you that the context window eats VRAM on top. A 32K-token context on an 8B model adds roughly 1–2 GB depending on architecture (the KV cache grows with both context length and layer count). So the honest rule for budgeting is: weights + ~2 GB for the KV cache + a little headroom = what you actually need in VRAM. I work through the exact numbers in Section 5.
2. Cross-platform installation, done deliberately
The install itself is one line on most systems, but the environment you install into changes the outcome more than the command does. Here is what to think about on each OS before you run anything.
Windows: the native installer vs. WSL2
OllamaSetup.exe installs the daemon as a background tray app and adds ollama to your PATH. Two things trip people up on Windows specifically:
- The native build uses CUDA for NVIDIA GPUs, but if you have an older GPU or no NVIDIA card, it silently falls back to CPU. Run
ollama --versionand checkollama psafter loading a model — if the GPU column is empty, you are on CPU. - If you plan to call Ollama from inside WSL2 while running it natively in Windows, remember the Windows daemon listens on
127.0.0.1only, and WSL2 has its own network namespace. When both halves are on the same machine you can usually reach the Windows daemon viahost.docker.internalor the machine’s LAN IP withOLLAMA_HOSTset appropriately.
For the full native-install, first-run, and CUDA-verification walkthrough, see How to Install Ollama on Windows.
Linux and Ubuntu server: you get a real service
On Linux the installer registers a proper systemd service, which is the biggest difference from Windows and macOS — you get auto-start, logging via journalctl -u ollama, and sane permission handling.
curl -fsSL https://ollama.com/install.sh | sh
systemctl status ollama
The important follow-ups most guides omit: the service runs as a dedicated ollama user (so models live under /usr/share/ollama/.ollama, not ~/.ollama), and on a headless box nothing listens on a reachable interface until you set OLLAMA_HOST. Remote access, firewalling to a specific LAN, and hardening are covered in How to Install Ollama on Ubuntu.
macOS: Metal and unified memory
Apple Silicon runs models through Metal directly in unified memory, which is why an 8 GB RAM Mac can sometimes run an 8B quant that would be tight on a 6 GB Nvidia card — there is no separate VRAM pool to overflow. Homebrew is the clean route:
brew install ollama
brew services start ollama
A practical tip: on 8–16 GB base-model Macs you will hit a wall faster than the GPU spec suggests, because system RAM is shared with the OS and other apps. Budget the model plus a few GB for macOS itself. More in How to Install Ollama on macOS.
3. The CLI, and what each command actually tells you
These are the commands you will use weekly, with the detail that matters.
| Command | Real use | Gotcha |
|---|---|---|
ollama pull <name>:<tag> |
Download weights without starting a chat. | Pick the : tag explicitly — ollama pull llama3.2 vs llama3.2:1b vs 3b are very different models. |
ollama run <name> |
Pull-if-missing, then open interactive chat. | Use /set parameter num_ctx 16384 inside the session to fix truncated replies on the fly. |
ollama list |
Installed models, tags, size on disk. | The size shown is what it occupies on disk, not how much VRAM it needs. |
ollama ps |
What’s loaded in memory right now and the GPU offload. | This is your VRAM diagnostic — the “PROCESSOR” column tells you if layers spilled to CPU. |
ollama show <name> --modelfile |
Print the exact recipe (FROM/SYSTEM/PARAMETER/TEMPLATE). | Great for figuring out what a community model was built from. |
ollama rm <name> |
Delete a model to reclaim disk. | Removes tags; orphaned blobs are reclaimed by ollama on its own schedule. See the delete models guide to reclaim eagerly. |
ollama cp <a>:<tag> <b>:<tag> |
Re-tag a model without re-downloading. | Instant, since it just adds a tag pointing at existing blobs. |
Where models land and how to relocate them to a bigger disk (a common early mistake — pulling a 70B quant fills your system drive overnight) is the subject of Where Ollama Stores Models & How to Move Them.
4. Modelfiles: packaging repeatable behavior, not just prompts
A Modelfile is Ollama’s declarative recipe. The typical tutorial shows a system prompt and a temperature, and that’s honestly 30% of the value. The other 70% is the parts that change how the model behaves under the hood: TEMPLATE, num_ctx, and the ability to FROM an already-custom model to layer behavior.
FROM qwen2.5-coder:7b
# A system prompt that changes the model's working style.
SYSTEM """You write production-grade Go and Python.
Prefer explicit error handling. Never return pseudo-code."""
# Sampling: lower temperature for deterministic code.
PARAMETER temperature 0.2
PARAMETER top_p 0.9
PARAMETER repeat_penalty 1.1
# The context a real repo-scope task needs. 8K is the default; 32K uses more VRAM.
PARAMETER num_ctx 32768
# Which device runs the layers: 0 = auto, -1 = CPU only, 99 = push all to GPU.
PARAMETER num_gpu 99
Two directives are worth understanding more than the rest:
num_ctxsets the context window the model is loaded with. This is the #1 cause of “it keeps forgetting our conversation.” The default is small; raise it for real tasks, but know each step up costs KV-cache VRAM.num_gpucontrols layer offloading.99means “use the GPU for everything it can.” On machines where the driver is flaky, some people pin-1(CPU-only) to force stability at the cost of speed.
Build and launch your tuned model with two commands:
ollama create repo-assistant -f ./Modelfile
ollama run repo-assistant
The three server-side variables you will actually reach for day to day are OLLAMA_HOST (where the daemon binds), OLLAMA_MODELS (where weights live), and OLLAMA_KEEP_ALIVE (how long loaded models stay resident). Each is covered where it applies below; for moving where models are stored, see Ollama Model Storage.
5. VRAM budgeting and GPU offload, with the math
The distinction that saves hours of confusion: a model either fits in VRAM and runs fast, or it spills to system RAM and runs slow — there isn’t really an in-between. Ollama will happily offload what doesn’t fit, but the moment layers hit CPU RAM you typically drop from hundreds to single-digit tokens per second.
Here is how to estimate VRAM before you download anything. A Q4_K_M 8B model is ~4.7 GB of weights. Add a 16K KV cache (~1 GB) and ~0.5 GB overhead, and you want ~6.5 GB of VRAM. On a 8 GB card that is right at the edge and will probably spill; on 12 GB it’s comfortable and fast. Use ollama ps after loading to confirm with the real number.
| Model | Best quant | Weights on disk | VRAM needed (16K ctx, comfortable) | Runs fully on |
|---|---|---|---|---|
| Llama 3.2 :1b | Q4_K_M |
~0.8 GB | ~1.5 GB | Any modern GPU / 8 GB Mac |
| Llama 3.2 :3b | Q4_K_M |
~2 GB | ~3.5 GB | GTX 1660 / RTX 3050 / 8 GB Mac |
| Qwen2.5 :7b | Q4_K_M |
~4.7 GB | ~6.5 GB | RTX 3060 12GB / 16 GB Mac |
| Qwen2.5 :14b | Q4_K_M |
~9.5 GB | ~12 GB | RTX 4070 12GB / 24 GB Mac |
| Qwen2.5 :32b | Q4_K_M |
~20 GB | ~24 GB | RTX 4090 24GB / 36 GB+ Mac |
| DeepSeek-R1 :70b or Llama 3.3 | Q4_K_M |
~40+ GB | ~46 GB | Dual 24GB GPUs / 64 GB+ Mac Studio |
If your generation rate “looks slow,” the fastest diagnosis is ollama ps — not the model’s advertised benchmarks. When “PROCESSOR” shows CPU/RAM, that’s your bottleneck, and the fix is either more VRAM, a smaller quant, a smaller model, or a truncated num_ctx. For the step-by-step NVIDIA/AMD driver setup and the out-of-memory debugging flow, pair this with the Ollama Troubleshooting guide.
6. The REST API: calling Ollama from your own code
The daemon exposes two families of endpoints on 11434: the native /api/* routes and an OpenAI-compatible /v1/* surface. If you are starting fresh, prefer the OpenAI-compatible route — it means you can point existing OpenAI SDK code at Ollama by swapping the base_url, and swapping back to a hosted model later is a one-line change.
Non-streaming generation via cURL
curl http://127.0.0.1:11434/api/generate -d '{
"model": "qwen2.5:7b",
"prompt": "Write a compliant .gitignore for a Node project in 40 words.",
"stream": false
}'
OpenAI-compatible chat (the portability win)
import openai
client = openai.OpenAI(base_url="http://127.0.0.1:11434/v1", api_key="ollama")
resp = client.chat.completions.create(
model="qwen2.5:7b",
messages=[{"role": "user", "content": "Explain RAG in two sentences."}],
)
print(resp.choices[0].message.content)
Two practical notes. First, streaming (stream: true, or stream=True in the SDK) is what makes long generations feel responsive in a UI — otherwise you wait for the whole completion. Second, keep_alive controls how long a model stays in memory after a request: the default unloads after 5 minutes, which is a common source of mysteriously slow “first” requests as a model reloads. To put a GUI front-end on top of this API for chat and document workflows, see Connecting AnythingLLM and Open-WebUI to Ollama.
7. Serving Ollama to other machines (and doing it safely)
By default OLLAMA_HOST binds to 127.0.0.1, so only localhost can reach it — which is correct and safe until you explicitly want LAN access. To expose it, set the bind address and restart:
# Linux server: listen on all interfaces
sudo systemctl stop ollama
sudo systemctl edit ollama
# add: [Service]
# Environment="OLLAMA_HOST=0.0.0.0:11434"
sudo systemctl daemon-reload
sudo systemctl start ollama
Before you do this, note the honest security reality: Ollama’s API has no built-in authentication. Binding to 0.0.0.0 on a public interface lets anyone on the network run your GPU. Only expose it if you have blocked the port at the firewall, put it behind a reverse proxy with auth, or trust every host on that LAN. OLLAMA_ORIGINS helps with browser-based CSRF-style calls from a web app, but it is not a substitute for a firewall. This is why so many published guides recommend OLLAMA_HOST=0.0.0.0 for “remote” and it quietly becomes a security issue.
8. Where Ollama fits next to the other local runtimes
Ollama is the popular middle ground, but it’s not the only player, and each alternative wins on a different axis:
- llama.cpp vs. Ollama: llama.cpp is the engine beneath Ollama. Running it directly (via
llama-server) exposes every flag and lets you script or embed inference with zero packaging; Ollama gives you a model registry, a managed daemon, and a friendlier API. If you need fine-grained control or plan to ship the engine inside your own app, llama.cpp wins; for daily server hosting, Ollama’s ergonomics usually win. - LM Studio vs. Ollama: LM Studio is a graphical app with model browsing, hardware meters, and a chat UI — ideal if you are not running a headless service. Ollama is lighter, scriptable, and better suited to API-driven and background use.
- vLLM: built for high-concurrency serving (PagedAttention, continuous batching). Running a 7B behind a REST endpoint for a handful of local users, vLLM is overkill; Ollama is the pragmatic local choice. For production multi-user throughput, vLLM leads.
If you want a full GUI on top of Ollama for chat and document workflows, see Connecting AnythingLLM and Open-WebUI to Ollama.
9. Diagnostics and fixes for the errors that actually happen
These are the failures I see most, with the real underlying cause rather than the copy-paste answer.
| Symptom | What’s really happening | Fix |
|---|---|---|
| Error: could not connect to ollama app | The daemon isn’t running or not reachable on 11434. | Start the service (sudo systemctl start ollama, or the tray app on Win/mac). Then curl 127.0.0.1:11434 to confirm. |
bind: address already in use |
Something else holds port 11434, or a stale process. | Find it with netstat -ano | findstr 11434 (Win) or ss -ltnp | grep 11434 (Linux), kill it, restart. |
CUDA out of memory |
Weights + KV cache exceed VRAM. | Lower num_ctx first (cheapest fix), then try a smaller quant, then a smaller model. |
Fast killing a process, then ollama list still shows the model |
You killed the runner, not the server, and tags persist on disk regardless. | Use ollama rm for a clean delete; don’t kill -9 the daemon to “remove” models. |
| First request is always slow, then fast | Model was unloaded by keep_alive between calls. |
Set keep_alive or OLLAMA_KEEP_ALIVE to keep it resident. |
For the full diagnostic workflow — reading journalctl -u ollama, checking GPU offload, CORS, and network cases — work through Ollama Troubleshooting.
Frequently Asked Questions
Is Ollama free and open-source?
Yes. The runtime is MIT-licensed and the models it pulls are open-weight. You pay nothing and there are no API rate limits or telemetry-based throttling; the only cost is your own hardware.
Where does Ollama keep models, and can I move them?
Defaults are C:\Users\<you>\.ollama\models (Windows), /usr/share/ollama/.ollama/models (Linux service), and ~/.ollama/models (macOS / Linux user install). Point OLLAMA_MODELS at a new directory before starting the daemon to relocate. Details and gotchas in the model storage guide.
Can I run Ollama without a GPU?
Yes, but know the trade-off: an 8B Q4 model runs at roughly 3–10 tokens/sec on a modern CPU versus 60–120 tokens/sec on a current GPU. Fine for interactive light use; painful for big context or long generations.
Why is the context window truncating my conversation?
Because num_ctx defaults are small. Either raise it in the Modelfile (PARAMETER num_ctx 32768) or set it per-session with /set parameter num_ctx inside ollama run. Watch VRAM when you go up.
How do I update Ollama?
On Windows/macOS the tray/menu app prompts you. On Linux, re-run curl -fsSL https://ollama.com/install.sh | sh; it replaces the binary and leaves your downloaded models untouched.
Can I run the same on my phone or another computer on my network?
Set OLLAMA_HOST to bind beyond localhost, allow the port through the firewall, and point whichever client or app you like at http://<machine-ip>:11434. Keep auth/firewalling in mind — there is no built-in password layer.