Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Cheat sheet

Ollama commands cheat sheet

Ollama CLI commands, in-chat commands, Modelfile instructions, environment variables and API endpoints on one page, checked against the Ollama docs and source.

By Checked Beginner
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
On this page

Every Ollama command, in-chat command, Modelfile instruction and server setting you are likely to need, checked against Ollama v0.40.17 (released 10 November 2026) and docs.ollama.com. Most people need four commands: ollama pull, ollama run, ollama ps and ollama rm. When a long prompt gets cut off, raise the context length first.

Everyday commands

Command What it does
ollama pull <model> Download a model
ollama run <model> Chat with a model in the terminal; pulls it first if needed
ollama run <model> "<prompt>" One answer, then exit (good for scripts)
ollama list (alias ollama ls) Models on disk
ollama ps Models loaded now, with size, CPU/GPU split, context and unload time
ollama stop <model> Unload a running model from memory
ollama rm <model> [<model>...] Delete one or more models from disk
ollama show <model> Model details; add --modelfile, --parameters, --template, --system or --license
ollama cp <source> <destination> Copy a model under a new name
ollama create <name> -f Modelfile Build a custom model from a Modelfile
ollama push <model> Upload a model to a registry
ollama serve (alias ollama start) Start the server yourself
ollama signin, ollama signout Sign in to or out of ollama.com (aliases login, logout)
ollama launch Set up and start a supported app, such as ollama launch claude
ollama -v Print the version

Useful flags for ollama run

# Show tokens per second and timings after each answer
ollama run gemma4 --verbose

# Keep the model loaded for 30 minutes after this run
ollama run gemma4 --keepalive 30m

# Ask for JSON output
ollama run gemma4 --format json "List three EU capitals as JSON"

# Thinking models: turn thinking on or off, or hide it
ollama run <model> --think=false
ollama run <model> --hidethinking

# Pipe a file in, or pass an image path to a vision model
cat notes.txt | ollama run gemma4 "Summarise these notes in five bullets"
ollama run gemma4 "What is in this image? ./photo.png"

In-chat commands

Type these at the >>> prompt inside ollama run.

Command What it does
/? or /help List commands; /? shortcuts lists keyboard shortcuts
/set parameter num_ctx 8192 Change the context length for this session
/set parameter temperature 0.2 Change any model parameter (see the table below)
/set system "<message>" Set the system message
/set format json, /set noformat Turn JSON mode on or off
/set verbose, /set quiet Show or hide timing stats
/set think, /set nothink Turn thinking on or off
/show info, /show modelfile, /show parameters Inspect the loaded model
/save <name>, /load <name> Save the session as a model, or load a model or session
/clear Clear the session context
/bye Exit
""" Start and end multi-line input

Modelfile template

FROM gemma4
PARAMETER temperature 0.3
PARAMETER num_ctx 8192
SYSTEM You are a careful assistant who answers in plain British English.

Build and run it with ollama create my-assistant -f Modelfile, then ollama run my-assistant. Print any model’s Modelfile with ollama show --modelfile <model>.

Instruction Use
FROM Required. Base model, a GGUF file or a Safetensors folder
PARAMETER Set a run parameter
SYSTEM System message
TEMPLATE Full prompt template, in Go template syntax
MESSAGE Seed history with system, user or assistant turns
LICENSE Licence the model is shared under
REQUIRES Minimum Ollama version
CAPABILITY Add a capability without removing inherited ones

Model parameters

Parameter Default in the Modelfile docs Effect
num_ctx 2048 (see the conflict below) Context window in tokens
temperature 0.8 Higher is more varied
top_k 40 Lower is more conservative
top_p 0.9 Works with top_k
min_p 0.0 Minimum probability relative to the top token
num_predict -1 (no limit) Maximum tokens to generate
repeat_penalty 1.0 (off) Penalise repetition
repeat_last_n 64 How far back to check for repetition
seed 0 Same seed and prompt give the same output
stop none Stop sequence; repeat the line for several

Sources disagree on the default context length. The Modelfile reference says 2048, the FAQ says 4096, and the context length page and the v0.40.17 source say it depends on VRAM: 4k under 24 GiB, 32k from 24 to 48 GiB, 256k at 48 GiB or more. Check the CONTEXT column of ollama ps for the real value.

Environment variables

Variable Default Use
OLLAMA_HOST 127.0.0.1:11434 Bind address; 0.0.0.0:11434 exposes it on your network
OLLAMA_CONTEXT_LENGTH 4k, 32k or 256k by VRAM Default context length for every model
OLLAMA_KEEP_ALIVE 5m How long a model stays loaded after its last request
OLLAMA_MODELS see below Where models are stored
OLLAMA_MAX_LOADED_MODELS 3 per GPU, or 3 on CPU Models loaded at once, if they fit
OLLAMA_NUM_PARALLEL backend default Parallel requests per model; more needs more memory
OLLAMA_ORIGINS 127.0.0.1, 0.0.0.0 Extra allowed browser origins, comma separated
OLLAMA_FLASH_ATTENTION model default 1 forces flash attention on, 0 off
OLLAMA_KV_CACHE_TYPE f16 q8_0 or q4_0 to save memory, for all models
OLLAMA_DEBUG off 1 for debug logs
OLLAMA_NO_CLOUD off Disable cloud models and web search

Default model folders: ~/.ollama/models on macOS, /usr/share/ollama/.ollama/models on Linux, C:\Users\%username%\.ollama\models on Windows. Run ollama serve --help for the full list.

Setting variables and reading logs

# macOS app: set, then quit and reopen Ollama
launchctl setenv OLLAMA_HOST "0.0.0.0:11434"

# Linux (systemd): add Environment="OLLAMA_CONTEXT_LENGTH=32768" under [Service]
sudo systemctl edit ollama.service
sudo systemctl daemon-reload
sudo systemctl restart ollama

# One-off, when you start the server yourself
OLLAMA_CONTEXT_LENGTH=32768 ollama serve

# Logs: macOS, then Linux
cat ~/.ollama/logs/server.log
journalctl -u ollama --no-pager --follow --pager-end

On Windows, open %LOCALAPPDATA%\Ollama and read server.log. On Linux, update by re-running curl -fsSL https://ollama.com/install.sh | sh; the macOS and Windows apps update themselves.

API endpoints

Local base URL: http://localhost:11434. The OpenAI-compatible API is under /v1, for example http://localhost:11434/v1.

Method and path What it does
POST /api/chat Next message in a chat
POST /api/generate Completion for a single prompt
POST /api/embed Embeddings
GET /api/tags Models on disk (same as ollama list)
GET /api/ps Loaded models (same as ollama ps)
POST /api/pull, DELETE /api/delete Download or delete a model
GET /api/version Server version

Send "keep_alive": 0 in a request to unload the model after it answers, or "options": {"num_ctx": 8192} to set the context length for that request.

Common mistakes

Mistake Fix
Long documents get silently cut off Raise num_ctx or OLLAMA_CONTEXT_LENGTH, then check CONTEXT in ollama ps
ollama ps shows a CPU/GPU split and answers are slow Use a smaller model or a shorter context so it fits in GPU memory (100% GPU)
Exported OLLAMA_HOST in your shell, but the app ignores it Set it with launchctl setenv (macOS) or systemctl edit (Linux) and restart Ollama
Set OLLAMA_HOST=0.0.0.0 on a laptop that joins shared networks Keep the default 127.0.0.1 unless other machines need it, and firewall port 11434 when they do
Disk fills up with old models ollama list, then ollama rm the ones you no longer use

Check it works

ollama -v
curl http://localhost:11434/api/version
ollama run gemma4 "Say hello in five words"
ollama ps

If all four answer, the server, a model and the API are working. New to running models yourself? Start with the Ollama tutorial, and compare Ollama with llama.cpp, vLLM and SGLang in the local model servers cheat sheet.

Check your understanding

Ollama commands quiz

Everyday Ollama commands, run flags, in-chat commands, Modelfiles, context length, environment variables and the local API.

7 questions · pass mark 70%

Question 1 of 70 answered
  1. You want to free memory used by a model you finished with, but keep it on disk. Which command fits?

Checked against

  • Run local models with Ollama

    Install Ollama, run an open-weight model on your own machine, call it from scripts over the local API and choose a model size your hardware can handle, offline.

    TutorialBeginner30 min

  • Local model servers cheat sheet

    Start commands, default ports and OpenAI-compatible base URLs for Ollama, LM Studio, llama.cpp, MLX LM, vLLM and SGLang, checked against each project's docs.

    Cheat sheetIntermediate

  • Local models

    Running open-weight models on your own hardware for privacy, cost or offline use.

    SkillBeginner

  • Context window

    The maximum number of tokens a model can consider in one request, covering both the input you send and the output it writes.

    Glossary

  • Quantization

    Storing model weights at lower numerical precision, such as 8 or 4 bits, to reduce memory use and speed up inference at a small quality cost.

    Glossary

Back to top