16Install & Master Ollama
Install Ollama on Mac, Windows, Linux or Docker, run your first model, and learn every command you'll use day to day — plus configuration, storage and troubleshooting.
What you'll learn
- Install Ollama on your operating system
- Download, run and manage models
- Configure context length, model storage and network access
- Troubleshoot the most common problems
Step 1 — Install
Download the app from ollama.com/download, unzip, and drag Ollama to Applications. Open it once — a llama icon appears in the menu bar and the ollama command becomes available. (Homebrew users: brew install ollama.)
ollama --version
Download OllamaSetup.exe from the Ollama download page and run it (no admin rights needed). Ollama runs in the system tray; NVIDIA and supported AMD GPUs are used automatically. Then open PowerShell:
ollama --version
The official script installs Ollama and registers it as a systemd service:
curl -fsSL https://ollama.com/install.sh | sh
systemctl status ollama # should say "active (running)"
Ideal for servers. CPU only:
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
docker exec -it ollama ollama run gemma3:4b
NVIDIA GPU (after installing the NVIDIA Container Toolkit):
docker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
Step 2 — Your first model
ollama run gemma3:4b
The first run downloads the model (a few GB), then drops you into a chat. Try: “Write three subject lines for a payment reminder email.” Type /bye to exit.
| Inside the chat | Does |
|---|---|
/? | Help: list all chat commands |
/set system <text> | Set a system prompt for this session |
/set parameter temperature 0.2 | Change a parameter on the fly |
/show info | Model details: parameters, context length, quantization |
""" | Start/end a multi-line message (paste long text) |
/bye | Exit |
Step 3 — Every command you need
ollama run qwen3:8b # download if needed + chat
ollama run qwen3:8b "Summarize: ..." # one-shot answer, no chat session
ollama pull gemma3:12b # download without running
ollama list # models on disk (+ size)
ollama ps # models loaded in memory right now (+ GPU/CPU split)
ollama show qwen3:8b # details: parameters, context, license
ollama stop qwen3:8b # unload from memory
ollama rm llama3.2:3b # delete to free disk space
ollama cp qwen3:8b my-assistant # copy/rename a model
ollama create name -f Modelfile # build a custom model (next lesson)
ollama serve # start the server manually (port 11434)
Pipe files in with your shell: cat notes.txt | ollama run qwen3:8b "Turn these notes into action items".
Step 4 — Configuration that matters
Ollama is configured with environment variables. Set them before starting the server (on Mac/Windows, set them and restart the Ollama app).
| Variable | What it does | Example |
|---|---|---|
OLLAMA_CONTEXT_LENGTH | Default context window for all models. Raise it for agents and long documents (uses more memory). | 16384 or 65536 |
OLLAMA_MODELS | Where models are stored — move them to a bigger drive. | /mnt/data/ollama |
OLLAMA_HOST | Address the server listens on. Default is local-only. | 0.0.0.0:11434 (LAN — see warning) |
OLLAMA_KEEP_ALIVE | How long a model stays loaded after use. | 30m, -1 (forever) |
OLLAMA_NUM_PARALLEL | Parallel requests per model. | 2 |
launchctl setenv OLLAMA_CONTEXT_LENGTH 16384
# then quit and reopen the Ollama app
setx OLLAMA_CONTEXT_LENGTH 16384
# then quit Ollama from the tray and start it again
sudo systemctl edit ollama
# add under [Service]:
# Environment="OLLAMA_CONTEXT_LENGTH=16384"
sudo systemctl restart ollama
Troubleshooting
| Problem | Fix |
|---|---|
| “could not connect to ollama” | The server isn't running — open the Ollama app or run ollama serve. |
| Very slow responses | Model too big for your GPU/RAM. Check ollama ps: if it shows CPU instead of GPU, use a smaller model or lower context. |
| Out of memory / crashes | Use a smaller model or a lower OLLAMA_CONTEXT_LENGTH; close other heavy apps. |
| Disk full | ollama list then ollama rm unused models, or move storage with OLLAMA_MODELS. |
| Model forgets earlier parts of a long chat or document | Context window too small — raise context length for that model. |
| Tool calls fail | Use a model tagged for tools (e.g. qwen3, llama3.1) and keep tool descriptions clear. |
Key takeaways
- Install once, then `ollama run
` downloads and chats in one step. - Core commands: run, pull, list, ps, show, stop, rm, create, serve.
- Raise OLLAMA_CONTEXT_LENGTH for agents and long docs; move storage with OLLAMA_MODELS.
- Never expose port 11434 publicly — use Tailscale or an authenticated proxy.
Knowledge check
0 / 3Q1Which command shows models currently loaded in memory?
`ollama ps` lists running models and whether they're on GPU or CPU.
Q2Default Ollama API port?
Ollama serves on localhost:11434 by default.
Q3Hermes needs a bigger context. What do you change?
OLLAMA_CONTEXT_LENGTH sets the default context window.