Ollama is the easiest way to run local LLMs, but most of its power is in commands and settings that the basic “ollama run” tutorial never shows: running a specific GGUF from Hugging Face, setting the context length, keeping a model loaded, moving the models folder, quantizing the KV cache, opening the API to your network, and calling it from code with the OpenAI or Anthropic formats. This cheat sheet collects every Ollama CLI command, the chat-window slash commands, the Modelfile instructions and parameters, every useful environment variable and the main API endpoints, checked against the current Ollama source and docs.
- Daily commands:
ollama run,pull,ls,ps,stop,rm,show,create. - Any GGUF from Hugging Face:
ollama run hf.co/USER/REPO-GGUF:Q4_K_M. - Bigger context:
OLLAMA_CONTEXT_LENGTH=32768, or/set parameter num_ctx 32768in the chat. - Save VRAM:
OLLAMA_KV_CACHE_TYPE=q8_0(with flash attention, which is automatic on supported GPUs). - Is it on the GPU?
ollama psand check the PROCESSOR column. - API:
http://localhost:11434, with native/api/chatplus OpenAI-style/v1/chat/completionsand Anthropic-style/v1/messages.
Install and Update
| System | Install |
|---|---|
| Linux | curl -fsSL https://ollama.com/install.sh | sh |
| Windows (PowerShell) | irm https://ollama.com/install.ps1 | iex, or the installer from ollama.com |
| macOS | Download the app from ollama.com |
| Docker | docker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama |
To update on Linux, run the install script again. The Windows and Mac apps update themselves; restart Ollama when it offers an update. Check your version with ollama -v.
Every CLI Command
| Command | What it does | Example |
|---|---|---|
ollama run MODEL [PROMPT] |
Downloads the model if needed and starts a chat, or answers one prompt | ollama run gemma4 "Why is the sky blue?" |
ollama pull MODEL |
Downloads or updates a model without running it | ollama pull qwen3.5 |
ollama list / ollama ls |
Lists downloaded models with size and date | ollama ls |
ollama ps |
Shows loaded models, memory use, CPU/GPU split and unload time | ollama ps |
ollama stop MODEL |
Unloads a model from memory now | ollama stop gemma4 |
ollama rm MODEL [MODEL...] |
Deletes one or more models from disk | ollama rm llama3.2 mistral |
ollama show MODEL |
Shows details: architecture, parameters, context length, quantization, capabilities | ollama show gemma4 --modelfile |
ollama create NAME -f Modelfile |
Builds a custom model from a Modelfile | ollama create mybot -f Modelfile |
ollama cp SOURCE DEST |
Copies a model under a new name (useful before editing) | ollama cp gemma4 gemma4-backup |
ollama push MODEL |
Uploads a model to your ollama.com account | ollama push yourname/mybot |
ollama serve |
Starts the server manually (the app normally does this) | OLLAMA_HOST=0.0.0.0 ollama serve |
ollama signin / signout |
Signs in to or out of ollama.com (aliases: login, logout) |
ollama signin |
ollama launch [APP] |
Sets up and starts a coding tool with an Ollama model | ollama launch claude --model qwen3.5 |
ollama -v |
Prints the version | ollama -v |
ollama serve --help |
Lists the environment variables your version supports | ollama serve --help |
ollama show also accepts --parameters, --template, --system, --license and -v for verbose details.
Useful ollama run Flags
| Flag | What it does |
|---|---|
--verbose |
Prints timings after each answer, including tokens per second. The quickest speed test |
--think=false / --think high |
Turns thinking off, or sets thinking level (true/false or high/medium/low) on models that support it |
--hidethinking |
Hides the thinking text but still lets the model think |
--keepalive 30m |
How long to keep the model loaded after this session |
--format json |
Forces JSON output |
--nowordwrap |
Disables word wrapping in the terminal |
--dimensions 256 |
For embedding models: shortens the output vector |
--voice NAME |
For speech models: picks the voice |
--insecure |
Allows pulling from a registry without HTTPS |
Handy patterns:
ollama run gemma4 --verbose "Summarise this in 3 bullets" < notes.txt ollama run gemma4 "What is in this image? ./photo.png" echo "Hello world" | ollama run nomic-embed-text ollama run gemma4 ""
The last one loads the model into memory without asking anything, so the first real request is instant. Recent versions also support decision models (--ask, --choice, --level) and speech models; run ollama run --help to see what your version has.
Slash Commands Inside the Chat
| Command | What it does |
|---|---|
/? or /help |
Lists commands; /? shortcuts lists keyboard shortcuts |
/set parameter num_ctx 16384 |
Changes a parameter for this session (any parameter from the table below) |
/set system "You are a concise assistant." |
Sets the system prompt |
/set think / /set nothink |
Turns thinking on or off |
/set verbose / /set quiet |
Shows or hides speed stats |
/set format json / /set noformat |
JSON mode on or off |
/set history / /set nohistory |
Saves or stops saving input history |
/set wordwrap / /set nowordwrap |
Word wrap on or off |
/show info |
Model details. Also /show modelfile, parameters, system, template, license |
/save mymodel |
Saves the current session (settings and conversation) as a new model |
/load mymodel |
Loads a saved session or switches model |
/clear |
Clears the conversation context |
/bye |
Exits (Ctrl+D also works) |
For multi-line input, wrap the text in triple quotes: type """, paste your text, and close with """. /set parameter num_gpu 20 sets how many layers go to the GPU, which is useful when a model almost fits.
Tip: /set parameter num_ctx 32768 followed by /save qwen-32k creates a permanent long-context version of a model without writing a Modelfile.
Run Any GGUF From Hugging Face
Ollama can pull GGUF files straight from Hugging Face, so you are not limited to the Ollama library:
ollama run hf.co/USER/REPO-GGUF ollama run hf.co/USER/REPO-GGUF:Q4_K_M ollama run hf.co/USER/REPO-GGUF:Q8_0
Without a tag it picks a default quant (usually Q4_K_M when available). Add the quant name as the tag to choose one. Not sure which quant to pick? Our GGUF quantization guide explains Q4_K_M, Q5_K_M, Q8_0 and IQ quants and which fits your VRAM.
For a GGUF you already downloaded, use a Modelfile (next section).
Modelfile Cheat Sheet
A Modelfile is a small text file that defines a custom model. Example:
FROM gemma4 PARAMETER temperature 0.4 PARAMETER num_ctx 16384 SYSTEM """You are a helpful assistant that answers in short, clear sentences."""
Build and run it:
ollama create mybot -f Modelfile ollama run mybot
| Instruction | What it does | Example |
|---|---|---|
FROM (required) |
Base model: a library model, a local GGUF file or a Safetensors folder | FROM ./model-Q4_K_M.gguf |
PARAMETER |
Sets a default parameter | PARAMETER num_ctx 32768 |
SYSTEM |
Default system prompt | SYSTEM """You are a pirate.""" |
TEMPLATE |
The full prompt template (Go template syntax with .System, .Prompt, .Response) | Usually copied from ollama show --template |
MESSAGE |
Adds example conversation turns (system, user or assistant) | MESSAGE user Is Paris in France? |
LICENSE |
Adds license text | LICENSE """MIT""" |
REQUIRES |
Minimum Ollama version | REQUIRES 0.14.0 |
CAPABILITY |
Declares an extra capability for the model | See the Modelfile docs |
Easiest way to customise an existing model: ollama show gemma4 --modelfile > Modelfile, edit the file, and create it under a new name. If a GGUF you imported gives broken or rambling output, it usually needs the right TEMPLATE; copy it from the same model in the Ollama library or from the official GGUF repo.
Ollama does not re-quantize GGUF files on import, so download the quant you want (or make it with llama.cpp’s llama-quantize). For a split GGUF, keep the original part names and point FROM at them with a wildcard. The -q flag of ollama create is only for quantizing Safetensors models (for example to nvfp4); the levels available depend on your version and hardware.
Model Parameters (num_ctx, temperature and more)
Use these in a Modelfile (PARAMETER name value), in the chat (/set parameter name value) or in the API options object.
| Parameter | What it controls | Typical values |
|---|---|---|
num_ctx |
Context window in tokens | 8192 to 32768 for chat; higher for long documents |
temperature |
Randomness (default 0.8) | 0.2 to 0.4 for facts and code; 0.7 to 1.0 for creative writing |
top_k |
Only consider the top K tokens (default 40) | 20 to 64 |
top_p |
Nucleus sampling (default 0.9) | 0.8 to 0.95 |
min_p |
Drops tokens far less likely than the top one | 0.05 to 0.1 |
repeat_penalty |
Penalises repetition (default 1.0, off) | 1.05 to 1.15 if a model loops |
repeat_last_n |
How far back repetition is checked (default 64) | 64 to 256 |
num_predict |
Maximum tokens to generate (default -1, no limit) | 512 to 4096 |
seed |
Fixed seed for repeatable output | Any number |
stop |
Stop sequences (can be repeated) | PARAMETER stop "User:" |
num_gpu |
Number of layers sent to the GPU | Lower it if a model crashes for lack of VRAM |
draft_num_predict |
Speculative draft tokens per step when a draft model or MTP is available | Leave default unless the model card says otherwise |
Always prefer the model card’s recommended temperature and sampling values; many recent models publish them.
Environment Variables
These configure the Ollama server. They apply to every model.
| Variable | What it does | Example |
|---|---|---|
OLLAMA_HOST |
Address and port the server listens on (default 127.0.0.1:11434) | 0.0.0.0:11434 to allow other devices |
OLLAMA_MODELS |
Folder where models are stored | D:/ollama-models |
OLLAMA_CONTEXT_LENGTH |
Default context length when not set elsewhere | 32768 |
OLLAMA_KEEP_ALIVE |
How long models stay loaded after use (default 5m); -1 keeps them forever, 0 unloads at once | 30m, -1 |
OLLAMA_FLASH_ATTENTION |
Force flash attention on (1) or off (0). It is automatic on supported hardware | 1 |
OLLAMA_KV_CACHE_TYPE |
KV cache precision: f16 (default), q8_0 (half the memory), q4_0 (a quarter) | q8_0 |
OLLAMA_NUM_PARALLEL |
Parallel requests per model (default 1). Memory use grows with this times the context | 2 |
OLLAMA_MAX_LOADED_MODELS |
How many models can be loaded at once (default 3 per GPU, or 3 on CPU) | 1 |
OLLAMA_MAX_QUEUE |
Requests queued before returning 503 (default 512) | 1024 |
OLLAMA_ORIGINS |
Extra web origins allowed to call the API | chrome-extension://* |
OLLAMA_GPU_OVERHEAD |
VRAM to keep free per GPU, in bytes | 1073741824 (1 GB) |
OLLAMA_SCHED_SPREAD |
Always spread models across all GPUs | 1 |
OLLAMA_LOAD_TIMEOUT |
How long a stalled model load may take before giving up (default 5m) | 15m for huge models on slow disks |
OLLAMA_NO_CLOUD |
Disables cloud features (remote models and web search) | 1 |
OLLAMA_DEBUG |
Extra debug logging | 1 |
OLLAMA_NOPRUNE |
Do not prune unused model blobs at startup | 1 |
OLLAMA_IGPU_ENABLE |
Allow integrated GPUs | 1 |
OLLAMA_NOHISTORY |
Do not save chat input history | 1 |
OLLAMA_MAX_TRANSFER_STREAMS |
Parallel streams for Safetensors model downloads and uploads (default 4) | 8 |
Run ollama serve --help to see the exact list for your version.
How to Set Environment Variables (Windows, Mac, Linux)
Windows
- Quit Ollama from the system tray.
- Open Start, search for “environment variables” and choose “Edit environment variables for your account”.
- Click New, enter the name (for example
OLLAMA_CONTEXT_LENGTH) and value (32768). - Click OK, then start Ollama again from the Start menu.
macOS
launchctl setenv OLLAMA_CONTEXT_LENGTH 32768 launchctl setenv OLLAMA_HOST "0.0.0.0:11434"
Then quit and reopen the Ollama app.
Linux (systemd)
sudo systemctl edit ollama.service
Add the variables under a [Service] section:
[Service] Environment="OLLAMA_HOST=0.0.0.0:11434" Environment="OLLAMA_KV_CACHE_TYPE=q8_0"
Save, then reload and restart:
sudo systemctl daemon-reload sudo systemctl restart ollama
One-off (any OS terminal running ollama serve)
OLLAMA_CONTEXT_LENGTH=32768 OLLAMA_KV_CACHE_TYPE=q8_0 ollama serve
Context Length and Memory
Context length is the setting people most often get wrong. If it is too small, the model forgets the start of a long document or conversation without warning. If it is too big, the KV cache fills your VRAM and part of the model moves to the CPU.
In current Ollama builds, the default context depends on your total VRAM:
| Total VRAM | Default context |
|---|---|
| Under about 24 GB | 4,096 tokens |
| About 24 to 47 GB | 32,768 tokens |
| About 48 GB and above | 262,144 tokens |
So on an 8, 12 or 16 GB card, the default is only 4K, which is short for documents, coding tools and RAG. Raise it in one of four ways, from most to least specific:
- API:
"options": {"num_ctx": 32768}in the request. - Chat:
/set parameter num_ctx 32768. - Modelfile:
PARAMETER num_ctx 32768. - Server default:
OLLAMA_CONTEXT_LENGTH=32768.
To fit a longer context in the same VRAM, set OLLAMA_KV_CACHE_TYPE=q8_0, which halves the cache with very little quality loss. Our GGUF guide has a KV cache size table so you can estimate what fits.
Estimate for a 16 GB card like the RTX 5080: an 8B model at Q4_K_M (about 5 GB) with a 32K context and a q8_0 KV cache needs roughly 8 GB in total, leaving room for a larger model or a longer context. This is an estimate, not a measured result.
Check GPU Use and Fix Slow Models
Run ollama ps while a model is loaded:
NAME ID SIZE PROCESSOR UNTIL gemma4 a1b2c3d4e5f6 9.6 GB 100% GPU 4 minutes from now
- 100% GPU: everything is in VRAM. Best speed.
- 48%/52% CPU/GPU: the model or its context did not fit, and generation will be much slower.
- 100% CPU: no GPU in use. Check drivers, or the GPU is not supported.
If it shows a CPU/GPU split: lower num_ctx, set OLLAMA_KV_CACHE_TYPE=q8_0, pick a smaller quant, or set OLLAMA_MAX_LOADED_MODELS=1 so other models are not taking VRAM. Use ollama run MODEL --verbose to measure tokens per second before and after.
Logs are the next step if a model fails to load. On Windows they are in %LOCALAPPDATA%\Ollama (server.log); on Linux use journalctl -u ollama; on Mac they are in ~/.ollama/logs/server.log.
Where Models Are Stored and How to Move Them
| System | Default folder |
|---|---|
| Windows | C:\Users\%username%\.ollama\models |
| macOS | ~/.ollama/models |
| Linux (installer) | /usr/share/ollama/.ollama/models |
To move them to a bigger drive, quit Ollama, move the whole models folder, set OLLAMA_MODELS to the new path and start Ollama again. On Linux, give the ollama user access: sudo chown -R ollama:ollama /path/to/models.
Models are stored as hashed “blobs” plus small manifest files, so you will not see readable .gguf names in that folder. Use ollama ls to manage them, and ollama rm to free space.
API Cheat Sheet
The server listens on http://localhost:11434. Main native endpoints:
| Method and path | Purpose |
|---|---|
POST /api/chat |
Chat with message history, tools, images and structured output |
POST /api/generate |
Single prompt completion |
POST /api/embed |
Embeddings (newer endpoint; /api/embeddings is the older one) |
GET /api/tags |
List local models |
GET /api/ps |
List loaded models |
POST /api/show |
Model details |
POST /api/pull / /api/push |
Download or upload a model |
POST /api/create / /api/copy, DELETE /api/delete |
Create, copy or delete models |
GET /api/version |
Server version |
Compatible endpoints let you point existing apps at Ollama:
- OpenAI style:
/v1/chat/completions,/v1/completions,/v1/embeddings,/v1/models,/v1/responses, plus audio endpoints for speech models. - Anthropic style:
/v1/messages.
Chat request
curl http://localhost:11434/api/chat -d '{
"model": "gemma4",
"messages": [{"role": "user", "content": "Give me 3 names for a cat"}],
"stream": false,
"options": {"num_ctx": 16384, "temperature": 0.7}
}'
Keep a model loaded, or unload it
curl http://localhost:11434/api/generate -d '{"model": "gemma4", "keep_alive": -1}'
curl http://localhost:11434/api/generate -d '{"model": "gemma4", "keep_alive": 0}'
Structured JSON output
curl http://localhost:11434/api/chat -d '{
"model": "gemma4",
"messages": [{"role": "user", "content": "Tell me about Canada"}],
"format": {"type": "object", "properties": {"capital": {"type": "string"}, "population": {"type": "number"}}, "required": ["capital", "population"]},
"stream": false
}'
OpenAI Python client
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
r = client.chat.completions.create(model="gemma4", messages=[{"role": "user", "content": "Hello"}])
print(r.choices[0].message.content)
The API key can be any text for a local server; it is only required by the client library.
On Windows Command Prompt the single quotes in the curl examples do not work; use PowerShell’s Invoke-RestMethod, Git Bash or WSL, or put the JSON in a file and use curl ... -d @request.json.
ollama launch and Cloud Features
ollama launch sets up coding tools to use an Ollama model. Current versions support OpenCode, Claude Code, Codex, VS Code and Droid:
ollama launch ollama launch claude --model qwen3.5 ollama launch droid --config
Ollama also offers optional cloud models and web search when you sign in. Your prompts to local models stay on your machine. To turn cloud features off completely, set OLLAMA_NO_CLOUD=1.
FAQ
How do I see which models I have?
ollama ls. Use ollama ps to see which ones are loaded in memory right now.
How do I make Ollama use more of my GPU?
Check ollama ps. If it shows a CPU/GPU split, reduce the context, quantize the KV cache, choose a smaller quant or unload other models. Ollama always tries to put as much as possible on the GPU.
How do I access Ollama from another computer?
Set OLLAMA_HOST=0.0.0.0:11434, restart Ollama and use http://YOUR-PC-IP:11434. Ollama has no login, so only do this on a trusted network.
Why does my model forget earlier messages?
The context window is full. The default is only 4K tokens on GPUs under 24 GB. Raise num_ctx.
How do I update a model?
Run ollama pull MODEL again. Only changed parts are downloaded.
Can Ollama run image generation models?
Ollama is built mainly for language, vision, embedding and speech models, and any image generation support it has is limited and experimental. For full image and video workflows, use ComfyUI; our ComfyUI model folder cheat sheet is a good place to start.
Final Thoughts
Most Ollama problems come down to three settings: the context length (too small by default on most consumer GPUs), where the model is running (check ollama ps) and how long it stays loaded. Learn run, ps, show and create, set OLLAMA_CONTEXT_LENGTH and OLLAMA_KV_CACHE_TYPE once, and use hf.co/ tags to run any GGUF you like.
More local AI guides:
- GGUF Quantization Explained
- Liquid AI LFM3: Run It Locally
- MiniCPM-V 4.7 Locally
- Nemotron 3.5 Bolt E4B
- ComfyUI Command Line Arguments
Sources
- GitHub: ollama/ollama (README, CLI and server source)
- Ollama FAQ (environment variables, context, keep alive, KV cache)
- Ollama Modelfile reference
- Ollama API reference