Open-Source Wikis

/

Ollama

/

Ollama

/

Getting started

ollama/ollama

Getting started

This page covers building Ollama from source. To install a prebuilt binary, see ollama.com.

Prerequisites

Platform Required Optional
All Go ≥ 1.24, C/C++ compiler
macOS (Apple Silicon) Xcode command-line tools
macOS (Intel) CMake
Linux GCC or Clang, CMake NVIDIA CUDA, AMD ROCm
Windows Visual Studio 2022 (Native Desktop), CMake, TDM-GCC or llvm-mingw NVIDIA CUDA, AMD ROCm + Ninja

The full list with version notes is in docs/development.md.

Build

From the repository root:

# Apple Silicon: everything is built into the Go binary
go run . serve

# macOS Intel / Linux / Windows: build the native shims first
cmake -B build
cmake --build build
go run . serve

The CGO bindings into llama/llama.cpp/ can drift after upstream syncs. If you see crashes or link errors, run go clean -cache and rebuild (docs/development.md).

Run a model

# in one shell
go run . serve

# in another
go run . pull gemma3
go run . run gemma3

ollama serve listens on OLLAMA_HOST (default 127.0.0.1:11434). The CLI reads the same variable to find the daemon. Other useful environment variables are listed in envconfig/config.go and on the reference/configuration page.

Layout cheat sheet

.
├── main.go                 # process entry point
├── cmd/                    # CLI commands and TUI
│   ├── cmd.go              # cobra command tree
│   ├── interactive.go      # ollama run REPL
│   ├── launch/             # ollama launch integrations
│   └── tui/                # bubbletea selectors and signin
├── server/                 # HTTP daemon (gin)
│   ├── routes.go           # all routes
│   ├── sched.go            # model load scheduler
│   ├── images.go           # local model store
│   ├── download.go         # registry pulls
│   ├── upload.go           # registry pushes
│   └── cloud_proxy.go      # cloud-only model proxy
├── api/                    # Go client and shared types
├── llm/                    # llama.cpp subprocess wrapper (LlamaServer)
├── runner/                 # subprocess entry points
│   ├── llamarunner/        # CGO llama.cpp runner
│   └── ollamarunner/       # pure-Go runner
├── ml/, model/             # tensor and model definitions for ollamarunner
├── llama/                  # vendored llama.cpp + CGO bindings
├── x/                      # extended runtime (mlxrunner, imagegen, agent, ...)
├── parser/                 # Modelfile parser
├── convert/                # safetensors -> GGUF conversion
├── discover/               # GPU/CPU detection
├── envconfig/              # environment variable plumbing
├── middleware/             # OpenAI/Anthropic translation
├── openai/, anthropic/     # compat handlers
├── tools/                  # tool-call parser
├── thinking/               # reasoning-token parser
├── harmony/                # GPT-OSS harmony format parser
├── template/               # Go template engine for chat templates
├── tokenizer/              # tokenizer implementations
├── kvcache/                # KV cache implementations
├── readline/               # ollama run line editor
├── progress/               # download/build progress bars
├── format/                 # human formatters (size, duration, etc.)
├── auth/                   # SSH-key based auth
├── manifest/               # OCI-ish manifest types
├── fs/ggml/, fs/gguf/      # GGUF parsing
├── docs/                   # user-facing docs (rendered to docs.ollama.com)
├── app/                    # desktop app (Windows tray, macOS dialogs)
├── integration/            # integration tests
├── scripts/                # build/release helpers
└── version/                # build-stamped version string

Test

go test ./...                     # unit tests
go test -race ./...               # with race detector
go test -tags=integration ./integration/...   # integration suite (requires a GPU + models)

The lint config is .golangci.yaml. Run it with golangci-lint run.

Sync llama.cpp

The vendored llama.cpp tree under llama/llama.cpp/ is updated through Makefile.sync. When upstream changes, run make -f Makefile.sync to refresh patches and regenerate llama/build-info.cpp.

Where next

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Getting started – Ollama wiki | Factory