Run a local AI model with Ollama

Install Ollama, download and chat with an open model on your own machine, and call it from code through its local REST API on port 11434.

5 steps⏱ 15 minBeginnerLinux · macOS · Windows✓ Verified 4 Nov 2026

Showing commands for This recipe doesn't cover this OS yet.

Ollama downloads open-weight models and runs them locally. Your prompts never leave your machine, and it works offline once a model is downloaded.

Install Ollama

Linux · macOSbash
curl -fsSL https://ollama.com/install.sh | sh
WindowsPowerShell
irm https://ollama.com/install.ps1 | iex

Nothing to run on for this part.

Prefer a regular installer? Download Ollama.dmg (macOS) or OllamaSetup.exe (Windows) from ollama.com/download. Piping a script into a shell runs it straight away, so if you want to check it first, open the URL in your browser and read it.

Check that it’s installed and running

All systemsbash
ollama -v
All systemsExpected output
ollama version is 0.x.x
Linuxbash
# On Linux the installer sets up a systemd service
sudo systemctl status ollama

Nothing to run on for this part.

On macOS and Windows, Ollama runs as a menu-bar/tray app. If ollama says it can’t connect, start the app (or run ollama serve in another terminal).

Chat with a model

The first run downloads the model, which can take a few minutes.

All systemsbash
ollama run gemma4
All systemsExpected output
pulling manifest
pulling 4f5e...: 100% ▕████████████████▏ 
success
>>> Send a message (/? for help)

Nothing to run on for this part.

Type a question and press Enter. Type /bye to exit.

Manage your models

All systemsbash
ollama ls            # models you've downloaded
ollama ps            # models loaded in memory right now
ollama stop gemma4  # unload a model from memory
ollama pull gemma4  # download or update without chatting
ollama rm gemma4    # delete a model to free disk space

Nothing to run on for this part.

Call the model from code (REST API)

Ollama serves an API on http://localhost:11434. "stream": false returns one JSON reply instead of a stream of chunks.

Linux · macOSbash
curl http://localhost:11434/api/chat -d '{
  "model": "gemma4",
  "messages": [{ "role": "user", "content": "Why is the sky blue?" }],
  "stream": false
}'
WindowsPowerShell
$body = @{
  model    = "gemma4"
  messages = @(@{ role = "user"; content = "Why is the sky blue?" })
  stream   = $false
} | ConvertTo-Json -Depth 5
Invoke-RestMethod -Uri http://localhost:11434/api/chat -Method Post -ContentType "application/json" -Body $body
All systemsExpected output
{"model":"gemma4","created_at":"...","message":{"role":"assistant","content":"The sky looks blue because..."},"done":true,...}

Nothing to run on for this part.

Troubleshooting

ollama says it can’t connect to the server: on Linux run sudo systemctl start ollama. On macOS/Windows open the Ollama app.

Very slow answers: the model may be too big for your RAM/GPU. Try a smaller variant (many models have tags like :2b or :4b on ollama.com/library), and check ollama ps to see whether it’s running on GPU or CPU.

Update Ollama: on Linux, run the install command from step 1 again. On macOS/Windows, the app updates itself.

Clean up

Linuxbash
# Stop and disable the service (Linux)
sudo systemctl stop ollama
sudo systemctl disable ollama
macOS · Windowsbash
# Quit Ollama from the menu bar / system tray, then remove models you don't need:
ollama rm gemma4

Nothing to run on for this part.

Sources

Commands checked against these official sources on 4 Nov 2026. Found something out of date? Open an issue.

  1. Ollama README (install commands, REST API example) · Ollama on GitHub
  2. Ollama on Linux (systemd service, manual install, updates) · Ollama Docs
  3. Ollama CLI reference · Ollama Docs
  4. Ollama API reference · Ollama Docs
  5. Ollama model library · Ollama