How do I use Ollama?

4 min readMarkdown

Ollama is a free, open-source runtimeRuntimeThe software that loads a model file and runs it.Read more that runs as a background service. You pull models by name, run them from the terminal, and any app on your machine can use them through an API on port 11434.

A background service with an API

Install it from ollama.com. On Mac and Windows it installs a small app that starts the service at login. On Linux the install script sets it up as a system service.

Download the app from ollama.com and drag it to Applications. Or use Homebrew:

shell
brew install ollama

Download and run the installer from ollama.com. The service starts in the system tray.

shell
curl -fsSL https://ollama.com/install.sh | sh

Once it runs, the service listens on http://localhost:11434. It speaks its own API and the OpenAI-compatible one at /v1. Chat apps, coding tools and your own scripts all connect there. How do I call a local model from code? has the code.

Under the hood Ollama runs its own engine, built on the same ggml library as llama.cpp, and reads GGUFGGUFThe single-file model format used by llama.cpp and the apps built on it.Read more files. You never handle the files directly. Ollama stores them in its own folder by name.

Pull, run, list, remove

Five commands cover daily use.

shell
ollama pull qwen3:8b      # download a model
ollama run qwen3:8b       # chat in the terminal, pulls first if needed
ollama list               # models on disk, with sizes
ollama ps                 # models loaded in memory right now
ollama rm qwen3:8b        # delete a model from disk

The part after the colon is a tag. It picks the size and sometimes the What is quantization?. Each model's page on ollama.com lists its tags.

With no tag you get latest, which is usually a 4-bit build of a mid-sized variant.

Type /bye to leave a chat. ollama stop qwen3:8b unloads a model without deleting it.

Try it
shell
ollama run qwen3:8b --verbose

Ask it anything. After each answer, --verbose prints the prompt eval rate and eval rate, which are your prefillPrefillThe phase where the model reads your prompt. Limited by compute.Read more and decodeDecodeThe phase where the model writes its answer one token at a time. Limited by memory bandwidth.Read more speeds.

ollama ps is worth running whenever things feel slow. Its processor column shows how much of the model sits on the GPU. Anything other than 100% GPU means part of the model runs on the CPU. Why is my GPU not being used? covers what to do.

The Modelfile

A Modelfile is a short text file that builds a new model from an existing one. Use it to bake in settings such as context length or a system promptSystem promptStanding instructions placed before the conversation.Read more.

FROM qwen3:8b
PARAMETER num_ctx 32768
PARAMETER temperature 0.6
SYSTEM You are a concise assistant. Answer in plain English.

Build it and run it under a new name:

shell
ollama create qwen3-32k -f Modelfile
ollama run qwen3-32k

The new model shares the weightsWeightsThe full set of a model's parameters, stored in a file.Read more with the original, so it costs almost no disk space. ollama show qwen3:8b --modelfile prints the Modelfile of any model you have, which is a good starting point. Should I touch temperature and the other sliders? explains temperatureTemperatureHow much randomness goes into picking each token.Read more and the other PARAMETER options.

Context length

Ollama's default context is about 4K tokens on most machines. That is enough for a short chat. It is far too small for coding agents and document work, which need 32K tokens or more.

When the conversation outgrows the window, Ollama drops the oldest tokensTokenA chunk of text, usually part of a word. Models read and write in tokens.Read more without telling you. The model forgets your instructions, loses the file it was editing, or loops. This is the most common reason an agent "works in the cloud but not locally". How much can the model keep in mind? explains why.

There are three ways to raise it.

  1. For every model: Set the OLLAMA_CONTEXT_LENGTH environment variable before the service starts, for example to 32768. Restart Ollama after changing it.
  2. For one model, permanently: Use a Modelfile with PARAMETER num_ctx, as above.
  3. For one session: Inside ollama run, type /set parameter num_ctx 32768.

API clients can also send num_ctx in the request options on Ollama's native API.

The catch

A longer context costs memory. The KV cacheKV cacheSaved work from earlier tokens, so the model does not reread the whole conversation for every new token.Read more grows with every token of context, and a model that fit at 4K can spill onto the CPU at 64K. Check ollama ps after raising it, and if the GPU share drops, pick a smaller context or a smaller model.

Launching coding tools

Ollama has a launch command that sets up a coding tool to use a local model and starts it. It saves you editing the tool's config by hand.

shell
ollama launch

Whatever starts the tool, the context rule above still applies. A coding agent on a 4K window fails in confusing ways. Can I run a coding agent on a local model? covers which models hold up.

Where it trades speed for convenience

Ollama chooses settings for you, and the choices favour "it works" over "it is fast".

  • Engine age: Ollama's engine does not track every daily llama.cpp change. New models and faster kernels can reach llama.cpp first.
  • Hidden settings: Batch size, thread count and GPU layer splitPipeline parallelThe model is cut into consecutive slices across devices. Adds memory, not speed.Read more are picked automatically. You can override some, but not all, through Modelfile parametersParameterOne learned number inside a model. An 8B model has about eight billion of them.Read more and environment variables.
  • Mac format: On a Mac, Ollama runs GGUF on Metal. An MLXMLXApple's machine learning framework for Apple silicon.Read more build in MLX or LM Studio is often faster on the same machine.
  • Unloading: Models unload after a few idle minutes by default. The next request waits for a reload. Set OLLAMA_KEEP_ALIVE to keep them in memory longer.
Rule of thumb

Use Ollama when you want models available to every app with no fuss. Drop to llama.cpp when you need the last bit of speed or a setting Ollama does not expose.

Go deeperThat's enough

Useful environment variables

The service reads its settings from environment variables at startup. These are the ones that change behaviour most.

VariableWhat it does
OLLAMA_HOSTAddress to listen on. Set 0.0.0.0 to serve other machines on your network
OLLAMA_CONTEXT_LENGTHDefault context for every model
OLLAMA_KEEP_ALIVEHow long an idle model stays loaded. -1 keeps it loaded
OLLAMA_NUM_PARALLELRequests served at once per model
OLLAMA_FLASH_ATTENTION1 turns on flash attention
OLLAMA_KV_CACHE_TYPEq8_0 or q4_0 to shrink the KV cache. Needs flash attention

On a Mac, the app ignores variables set in your shell profile. Set them with launchctl setenv and restart the app. On Linux, add them to the systemd service with systemctl edit ollama.

Running models from Hugging Face

Ollama can pull GGUF files straight from Hugging Face by repository name, with a quantizationQuantizationStoring each weight with fewer bits so the model takes less memory.Read more tag.

shell
ollama run hf.co/bartowski/Qwen_Qwen3-8B-GGUF:Q4_K_M

That opens up any GGUF upload, not only the ones in Ollama's own library.

Sharing it on your network

Setting OLLAMA_HOST=0.0.0.0 exposes the API to every device on your network, with no password. Only do that on a network you trust. How do I share one model with my household or office? and Is local AI actually private? cover safer ways.