Contents

Ollama Tutorial: Run Open-Source LLMs Locally

Ollama is a tool that lets you run large language models (LLMs) on your own computer. With one command, you can download and chat with open-source models like Llama, Qwen, Gemma, DeepSeek, and gpt-oss. Your data stays on your device, and you don't pay per use.

ollama run gemma3

This Ollama tutorial starts with installation and takes you through connecting with Python, having a model return structured data, calling tools, and building your own local knowledge base for question answering (RAG).

What you'll learn

  • What Ollama is, what it can do, and what kind of computer you need
  • How to install Ollama on Windows, macOS, and Linux
  • How to choose a model and quantization level based on your graphics card's memory
  • How to build your own customized model with a Modelfile
  • How to connect to Ollama through its REST API, Python, and JavaScript
  • Structured output (JSON), tool calling (function calling), text embeddings, and RAG
  • How to deploy Ollama with Docker and pair it with Open WebUI to create a ChatGPT-like web interface

Who this is for

  • People who want to try open-source AI models locally
  • Teams that care about data privacy and don't want to send data to the cloud
  • Developers who want to add AI features to their own programs

You can get started as long as you know how to enter commands in a terminal. The programming integration chapters use basic Python or JavaScript.

Quick start

  1. Download and install Ollama from ollama.com (see Install Ollama).

  2. Open a terminal and run:

    ollama run gemma3
  3. When the model finishes downloading, type a question and press Enter to send it.

Start with What is Ollama?.

Getting started

  1. What is Ollama

    Learn what Ollama does, how it works, how it compares with cloud services like ChatGPT, its pros and cons, and what computer you need to run local AI models.

  2. Install Ollama

    Install Ollama on Windows, macOS, or Linux, verify GPU use, and learn how the Ollama service starts, updates, and uninstalls.

  3. Run your first model

    Download a model with ollama run and learn to chat, use interactive commands, enter multiline prompts, ask one-off questions, read files and images, and get Traditional Chinese replies.

  4. Choosing a Model and Hardware Requirements

    Learn to read 7B, 14B, and Q4_K_M labels, estimate VRAM needs, and choose Ollama models for chat, Chinese, coding, vision, and embeddings.

  5. Ollama Command Reference

    A complete guide to common Ollama commands: run, pull, list, ps, stop, rm, show, create, cp, serve, push, and signin, with options and practical examples.

Advanced settings

  1. Custom models with Modelfile

    Build your own Ollama model with a Modelfile. Set a system prompt and parameters, add example conversations, or import GGUF models from Hugging Face.

  2. Environment variables and configuration

    Learn how to configure Ollama environment variables for network access, model storage, context length, keep-alive time, and parallel requests on Windows, macOS, and Linux.

  3. GPU and performance tuning

    Check whether Ollama is using your GPU, fix CPU-only use, and improve speed with context length, KV cache quantization, Flash Attention, and model size.

  4. Run Ollama with Docker

    Run Ollama in Docker with the official ollama/ollama image, configure NVIDIA or AMD GPUs, persist model data, and launch Open WebUI with Docker Compose.

API and integrations

  1. REST API

    Get started with the Ollama REST API: chat, text generation, streaming, options, keep_alive, image input, thinking mode, and the OpenAI-compatible API.

  2. Python integration

    Use the official Ollama Python package to call local models with chat, streaming, multi-turn conversations, async, and remote hosts, or connect with the OpenAI Python SDK. Includes complete runnable examples.

  3. JavaScript integration

    Call Ollama from Node.js and browsers with the official ollama npm package. Learn chat, streaming, aborting requests, connection settings, fetch, and the OpenAI SDK.

  4. Structured outputs (JSON)

    Use Ollama's format parameter to return data that matches a JSON Schema. Define formats with Python Pydantic and JavaScript Zod for extraction, classification, and image data.

  5. Tool calling

    Let Ollama models call your functions to check weather, calculate values, and query databases. Learn the workflow with complete Python and REST API examples, including multiple tools and multi-turn calls.

  6. Embeddings and RAG

    Turn text into vectors with Ollama embedding models (bge-m3, nomic-embed-text), build semantic search, and create a local RAG knowledge base Q&A system in under 60 lines of Python. Covers chunking, similarity, and common improvements.

Integrations

  1. Open WebUI web interface

    Install Open WebUI and connect it to Ollama for local AI chat in a ChatGPT-like web interface. Covers Docker and pip, setup, accounts, document Q&A, custom models, and FAQs.

  2. Cloud Models

    Learn how Ollama cloud models run large models that your computer cannot handle, how to sign in and use them, API keys, privacy, and how to disable cloud features.

  3. FAQ and troubleshooting

    Find fixes for common Ollama issues, including connection failures, slow downloads, memory limits, unexpected answers, truncated output, and log access.

Updated October 12, 2026