Run a local LLM with Ollama
Ollama downloads a model and serves it with one command. It runs as a background service, loads models on demand and unloads them when idle. Under the hood it uses llama.cpp and GGUF files.
Pick Ollama when
- You want the shortest path from nothing to a running model.
- You switch between several models and want them loaded on demand.
- Your tools already speak the Ollama or OpenAI API.
Look elsewhere when
- You need a quantization Ollama does not publish for the model.
- You serve many users at once: vLLM batches far better.
1. Install
Linux
The install script sets up the binary and a systemd service.
macOS and Windows
Download the app from ollama.com/download. It installs the ollama command and keeps itself updated.
Check that it worked
2. Run a model
Example: Qwen 3.8 27B as Q4_K_M on NVIDIA GeForce RTX 4090 (24 GB). With a 16K context it needs 19.0 GB of 22.8 GB usable memory and should generate about 38–52 tok/s.
Size your own model and hardware for Ollama3. The settings that decide memory use
Set the context window
Ollama picks a default from your VRAM: 4K below 24 GB, 32K from 24 to 48 GB, 256K above. That default, not the model, decides how much memory the KV cache takes. Set it explicitly when you start the server, or with the slider in the app's settings.
Halve the KV cache
The KV cache can be stored in 8 bits instead of 16 when Flash Attention is active. The setting is global: it applies to every model the server loads.
Check what actually loaded
ollama ps shows the size in memory, the context length in use and the split between GPU and CPU. Anything other than 100% GPU means part of the model spilled into system memory and generation will be slow.
4. Connect your tools
Use it from other tools
The server listens on 127.0.0.1:11434. The native API lives under /api, an OpenAI-compatible one under /v1. Change the address with OLLAMA_HOST.
Or let your coding agent do it
Paste this into Claude Code, Codex or any agent with a shell. It carries the target, our estimates and the steps, and tells the agent to check the hardware first and to report measured memory and speed against the estimates. The calculator builds the same prompt for any model, hardware and runtime.
Set up a local LLM on this machine and verify that it works. Target - Model: Qwen 3.8 27B (Hugging Face: Qwen/Qwen3.8-27B) - Runtime: Ollama - Build: Q4_K_M, qwen3.8:27b - Context window: 16,384 tokens (16K) - Hardware this was sized for: NVIDIA GeForce RTX 4090 (24 GB) Estimates from llmsizing.com - Memory: 19.0 GB of 22.8 GB usable (weights 16.5 GB, KV cache 1.0 GB, approximate, overhead 1.5 GB) - Fit: Fits comfortably. 3.8 GB headroom left for a longer context or other apps. - Speed: 38–52 tok/s for one request. Scaled from 10 published llama.cpp measurements on this GPU. Steps 1. Check the hardware before downloading anything (`nvidia-smi`, or the vendor's equivalent). If it is not NVIDIA GeForce RTX 4090 (24 GB), or less than 19.0 GB of memory is free, stop and tell me what you found. 2. Check whether Ollama is installed with `ollama --version`. If it is not, install it: - Linux: `curl -fsSL https://ollama.com/install.sh | sh` - macOS and Windows: Download the app from ollama.com/download. It installs the `ollama` command and keeps itself updated. 3. Ollama's default context depends on VRAM, not on this plan. Start the server with OLLAMA_CONTEXT_LENGTH=16384 set (on Linux via the systemd unit's environment, on macOS via `launchctl setenv` or the app's settings), then restart it. 4. Start the model: `ollama run qwen3.8:27b` 5. Send one short test prompt. Then report, next to the estimates above: memory actually used (`ollama ps`), tokens per second, and whether everything runs on the GPU. 6. Tell me the base URL and model name to use from other tools. Ollama API: http://localhost:11434/v1. Rules - Ask me before using sudo, changing system settings or installing system packages. - Do not delete or replace models that are already on this machine. - If the download is larger than the free disk space, stop and tell me. - If the measured memory or speed is far from the estimates, say so plainly. Sized with https://llmsizing.com/?m=qwen3-8-27b&hw=rtx-4090-24gb&q=q4_k_m&ctx=16384&rt=ollama Setup guide: https://llmsizing.com/guides/ollama
How to read our numbers for Ollama
Weights are loaded once and the KV cache is allocated for the full context window up front, so memory use does not grow while you chat. Our numbers for Ollama use the file size of the exact tag from the Ollama registry.
- A model that does not fit is not refused: Ollama moves layers to the CPU and gets several times slower. Check
ollama ps. - Raising the context window after a model is loaded reloads it.