llama.cpp: install, GGUF models and llama-server
What llama.cpp is, how to install or build it with CUDA, Metal or Vulkan, run GGUF models from Hugging Face, and serve them with llama-server.
llama.cpp is the open-source (MIT) C/C++ engine that runs language models in the GGUF format on CPUs and GPUs, from a laptop to a server; Ollama and LM Studio both run models with it. Install it with brew install llama.cpp, the one-line installer from llama.app, a prebuilt archive from GitHub, or a cmake build with CUDA, Metal or Vulkan switched on. As of December 4, 2026 the newest tagged version is v1.1.1 and the newest nightly build is b13000. Run llama-server -hf ggml-org/gpt-oss-20b-GGUF:MXFP4 to download a model from Hugging Face and serve it with OpenAI-compatible and Anthropic-compatible APIs on 127.0.0.1:9931. The port was 8080 until October 2026, which is what most older guides and tools still expect.
What you get
llama.cpp is a library plus a set of programs around it, maintained by the ggml-org team on GitHub. Its README sets the goal as model inference “with minimal setup and state-of-the-art performance on a wide range of hardware”. The parts most people use:
llama-server, an HTTP server with OpenAI-style routes (chat completions, Responses, embeddings), an Anthropic Messages route, and a built-in chat page the project calls Llama Chat, at the server’s root address.llama-cli, a chat in the terminal.llama, a single command that wraps the others:llama serve(orllama server) runs the server and passes every flag after it through,llama cliopens the chat, andllama downloadfetches a model. It is what thellama.appinstaller puts on your machine, and what the README’s quick start now shows.
Ollama lists llama.cpp among its backends, and LM Studio runs GGUF models with it; both put their own model catalogues and apps around it (the Ollama vs LM Studio comparison covers both). Running llama.cpp directly means choosing the exact model file and quantisation, and setting the context window and the number of parallel requests yourself, which matters when a coding agent is the client.
Versions: tags and build numbers
llama.cpp has two numbering schemes, and it helps to know which one a package or a bug report means:
| Scheme | What it is | Newest, as of December 4, 2026 |
|---|---|---|
Build numbers, bNNNN | A build of the main branch, published as a GitHub release with binaries and marked pre-release. The llama.app installer installs these | b13000, December 4, 2026 |
Versions, vX.Y.Z | Semantic versions, from v0.1.0 on, cut as git tags that package managers build from (the release doc says so). The GitHub release for a version carries no binaries | v1.1.1, tagged December 4, 2026; Homebrew’s formula was on 1.1.0 |
llama version prints the build you have. A build you compile from a checkout is labelled as a development build unless you pass -DLLAMA_BUILD_IS_DEV=OFF.
Installing it
Pick by what you want to manage. Every route below gives you the same server; they differ in which build, which GPU backend, and how it updates.
| Route | Command | What you get |
|---|---|---|
The llama.app installer (macOS, Linux) | curl -LsSf https://llama.app/install.sh | sh | The newest build as one llama binary in ~/.local/bin, no sudo. On Linux it probes for CUDA, then ROCm, then Vulkan, and installs the build for the first it detects, or the CPU build. llama update updates it |
Homebrew (macOS, Linux) | brew install llama.cpp | Tagged versions (1.1.0 on December 4, 2026), with llama, llama-server, llama-cli and the other tools |
Windows | winget install llama.cpp or irm https://llama.app/install.ps1 | iex | Packaged build or the installer |
Other managers | sudo port install llama.cpp, nix profile install nixpkgs#llama-cpp, conda install -c conda-forge llama.cpp | conda-forge has CUDA, Vulkan and Metal builds |
GitHub release archives | Download from the releases page | Per build: Ubuntu CPU (x64, arm64), CUDA 12.8 and 13.5, Vulkan, ROCm 10.0, SYCL, OpenVINO; macOS; Windows |
Docker | ghcr.io/ggml-org/llama.cpp:server and :server-cuda, :server-cuda13, :server-vulkan, :server-rocm | Only llama-server; listens on 8080 inside the container |
Ubuntu’s own archive | sudo apt install llama.cpp | Build 8681 on 26.04 LTS (from April 2026), 10438 on 26.10: far behind, and from before the port change |
The installer is the quickest way onto a server, and it chooses the GPU build by probing the machine. Its script does not touch your shell profile; if ~/.local/bin is not on your PATH, it prints the line to add. To pin a build, set LLAMA_VERSION to a build number when you run it. A GitHub archive is the choice when you want one fixed build and the llama-server binary by that name: a Linux archive unpacks into a folder named after the build, such as llama-b13000, holding the programs and the libraries they need side by side, so run them from there.
Building from source, with a GPU backend
You need git, CMake and a C++ compiler. The CPU build, per the build guide:
git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp
cmake -B build
cmake --build build --config Release -j 8CopiedThe programs land in build/bin/, so the server is ./build/bin/llama-server. For a GPU, add one flag to the first cmake line and build again:
| Backend | Flag | Needs first |
|---|---|---|
Metal (Apple silicon) | None, on by default on macOS | Nothing |
CUDA (NVIDIA) | -DGGML_CUDA=ON | NVIDIA’s CUDA toolkit |
Vulkan (most GPUs) | -DGGML_VULKAN=1 | On Ubuntu or Debian, sudo apt-get install libvulkan-dev glslc spirv-headers; check with vulkaninfo |
ROCm (AMD) | -DGGML_HIP=ON with the HIPCXX and HIP_PATH the guide shows | ROCm |
Two snags the guide covers. A CUDA build on a machine whose GPU the compiler cannot see (a build box, a container) warns “Cannot find valid GPU for '-arch=native', default arch is used”; to build for the cards you mean, add -DGGML_NATIVE=OFF, or name the architectures, as in -DCMAKE_CUDA_ARCHITECTURES="86;89". And without libssl-dev installed the build still succeeds, without SSL support. Hugging Face serves models over HTTPS, so we read that as -hf downloads failing on such a build; install it before the first cmake.
Models: GGUF files and -hf
llama.cpp runs models stored as GGUF files, usually quantised to a few bits per weight so they fit in less memory. Hugging Face hosts thousands, and -hf downloads one by repository name, with the quantisation after a colon:
llama-server -hf ggml-org/gpt-oss-20b-GGUF:MXFP4CopiedThat file is 12.1 GB: gpt-oss-20b has about 21 billion parameters and a 131,072-token training window. Without a tag, -hf picks Q4_K_M, then Q4_K, then Q8_0, and otherwise the first GGUF file in the repository; a tag that matches nothing is an error. Downloads go to the standard Hugging Face cache, ~/.cache/huggingface/hub, shared with Python’s Hugging Face tools; llama.cpp moved there in March 2026, and that change migrated older downloads. LLAMA_CACHE overrides the location (then HF_HUB_CACHE and HF_HOME, in that order). Other things worth knowing:
- A gated or private repository needs a token in
HF_TOKEN, which-hfreads from the environment. --offlineuses only what is already in the cache, so a server never reaches the network after the first download.MODEL_ENDPOINTpoints-hfat a mirror that speaks the Hugging Face API.- A file already on disk loads with
-m /path/to/model.gguf. Models in other formats convert with the repository’sconvert_hf_to_gguf.py.
llama-server’s defaults
These come from the server README and the source as of December 2026. Each flag also has an environment variable, such as LLAMA_ARG_PORT or LLAMA_ARG_CTX_SIZE, listed beside it there.
| Setting | Flag | Default |
|---|---|---|
Address | --host | 127.0.0.1, this machine only |
Port | --port | 9931 (8080 before October 2026) |
API key | --api-key, --api-key-file | None: every request is accepted |
Context window | -c | 0, the model’s own maximum |
Parallel slots | -np | -1, auto: 4 slots sharing one cache |
Fit to memory | --fit | On: adjusts the arguments you did not set to fit in device memory |
Layers on the GPU | -ngl | auto |
Chat templates and tool calls | --jinja | On |
Model name the API reports | --alias | The model file’s path |
Built-in chat page | --no-ui turns it off | On |
Browser origins allowed (CORS) | --cors-origins | *, any |
Built-in file and shell tools | --tools, --agent | Off |
The routes a client uses, with their names in the README:
| Route | Speaks |
|---|---|
POST /v1/chat/completions | OpenAI Chat Completions |
POST /v1/responses | OpenAI Responses, converted internally to a chat completion |
POST /v1/messages, /v1/messages/count_tokens | Anthropic Messages, with streaming and tool use |
POST /v1/embeddings, /v1/completions | OpenAI embeddings and plain completions |
GET /v1/models | The loaded model (or, in router mode, those available) |
GET /health | 503 with "Loading model" until ready, then 200; needs no key |
Started with no model at all, llama-server runs in router mode: it lists the models in the cache (and in --models-dir), loads the one a request names in its model field, and keeps up to four loaded (--models-max). One model per server is simpler to reason about when an agent is the only client.
Port 9931, not 8080
For most of its life llama-server listened on 8080. In August 2026 the server gained a notice of the coming change, and from October 2026 (v0.7.0, whose notes say “Server now listens on port 9931 by default instead of 8080”) the default is 9931, chosen as leetspeak for GGML. Three places still use 8080: the Docker images, which keep it inside the container so tools built on them do not break; builds from before October, such as Ubuntu’s packages; and clients with a llama.cpp preset written for the old port. If a client gets “connection refused” on 8080 while the server’s listening on log line names 9931, change the client, or start the server with --port 8080.
Context size and parallel slots
A slot is one request being processed. How the context window is shared among them decides whether a long agent session fits:
- Auto (the default): 4 slots and a unified cache. Each slot can use the whole window, but the four draw on the same pool, so two long requests at once compete for it.
- A slot count you set, such as
-np 2: the cache is split, and each slot gets-cdivided by-np. With-c 131072 -np 2, each request has 65,536 tokens. --kv-unified-per-slot Nkeeps the shared pool and, without-c, sizes it to N times the slot count.
Set -c yourself for an agent. The default asks for the model’s whole training window, and with --fit on, the server adjusts arguments you left unset to fit in memory; our reading of that flag is that an unset window can come out smaller than you expect. Either way, the startup log says what you got, in the line initializing, n_slots = …, n_ctx_slot = …. That per-slot figure is the one to give the agent as its context limit. A coding agent’s system prompt and tool definitions take a large share of the window before you type anything, which is why agent makers and Ollama’s docs ask for 64K or more; the Hermes context-window guide shows one agent rejecting a smaller window.
Running llama-server as a service on Linux
On a server you want it to start at boot, restart if it crashes, and refuse requests without a key. First make a key file only the service account can read. This writes a random key without it ever appearing on a command line (replace you with the account that will run the server):
sudo mkdir -p /etc/llama-server
openssl rand -hex 32 | sudo tee /etc/llama-server/api-keys >/dev/null
sudo chown you /etc/llama-server/api-keys
sudo chmod 600 /etc/llama-server/api-keysCopiedFind the binary’s full path with command -v llama-server (or command -v llama after the llama.app installer, in which case the command below starts with /home/you/.local/bin/llama serve). Then create the unit; this opens an editor on a new file:
sudo systemctl edit --force --full llama-server.serviceCopied[Unit]
Description=llama.cpp server
After=network-online.target
Wants=network-online.target
[Service]
User=you
ExecStart=/home/you/llama.cpp/build/bin/llama-server -hf ggml-org/gpt-oss-20b-GGUF:MXFP4 --alias gpt-oss-20b -c 65536 -np 1 --api-key-file /etc/llama-server/api-keys
Restart=on-failure
[Install]
WantedBy=multi-user.targetCopiedStart it, follow the log, and check it from the server:
sudo systemctl enable --now llama-server
journalctl -u llama-server -fCopiedcurl -s http://127.0.0.1:9931/healthCopiedThe first start downloads the model into that account’s cache, and /health answers “Loading model” until it is ready. Once it is, you can add --offline to the command so later starts never go to the network. The key file takes one key per line, so each client can have its own; lines that start with # are comments. Clients send a key as Authorization: Bearer … or as x-api-key.
To give your own shell the key for the clients below, without typing it:
export LLAMA_API_KEY="$(sudo cat /etc/llama-server/api-keys)"CopiedReaching it from another machine
Leave it on 127.0.0.1 and forward the port over SSH. From your laptop, this makes the server’s llama-server answer at http://127.0.0.1:9931 locally, chat page included, until you stop the command (more on how this works in opening a localhost app on a remote server):
ssh -N -L 9931:127.0.0.1:9931 you@your-serverCopiedFor other machines of yours to reach it permanently, bind it to a private network address instead, such as the server’s Tailscale address with --host 100.x.y.z; a service bound to such an address can fail at boot if it starts before the network is up, and the fix for that is a short unit change. --host 0.0.0.0 listens on every interface, a public one included: on a machine with a public address that puts your model, and with no key your compute, in front of anyone who finds the port. Use it only behind a firewall that keeps 9931 closed to the internet, and always with a key.
Two security defaults matter here. The server answers browsers from any origin, with credentials allowed, and warns at startup when that is combined with no API key; our reading is that a web page open in a browser that can reach the server, through a tunnel for instance, could send it requests. A key closes that, as does --cors-origins localhost. And the experimental --tools and --agent flags give the model file reading, file writing and shell commands with the server’s own privileges, over the API; they are off by default, and the server refuses to start with them on a non-loopback address without a key.
Pointing coding agents at it
The examples assume the service above: the model reported as gpt-oss-20b, a 65,536-token slot, and the key in LLAMA_API_KEY. Change the three to match your own server. How well a local model drives an agent depends on the model and the window far more than on the client.
OpenCode
OpenCode 2 (2.4.4 as of December 4, 2026) finds Ollama, LM Studio and vLLM by itself, but not llama-server, so it goes in as a custom OpenAI-compatible provider, in ~/.config/opencode/opencode.json or a project’s own file (see OpenCode’s config guide for which wins). The shape follows the local-server example in its models docs:
{
"$schema": "https://opencode.ai/config.json",
"model": "llamacpp/gpt-oss-20b",
"providers": {
"llamacpp": {
"name": "llama.cpp",
"package": "@opencode/ai/providers/openai-compatible",
"settings": {
"baseURL": "http://127.0.0.1:9931/v1",
"apiKey": "{env:LLAMA_API_KEY}"
},
"models": {
"gpt-oss-20b": {
"modelID": "gpt-oss-20b",
"capabilities": { "tools": true, "input": ["text"], "output": ["text"] },
"limit": { "context": 65536, "output": 8192 }
}
}
}
}
}CopiedThe limit.context figure is what OpenCode compacts against; for a model it does not know, it otherwise assumes a 200,000-token window, far beyond what the server gives each slot. The same pattern with Ollama, and what goes wrong when the two figures disagree, is in OpenCode with Ollama.
Codex
Codex speaks only the Responses API to custom providers, and llama-server serves it at /v1/responses; since May 2026 it drops the Codex tool types it cannot run (web search, file search and others) instead of failing the request. Codex’s --oss switch knows only LM Studio and Ollama, so add a provider to ~/.codex/config.toml (the config.toml guide covers the file):
model = "gpt-oss-20b"
model_provider = "llamacpp"
model_context_window = 65536
[model_providers.llamacpp]
name = "llama.cpp"
base_url = "http://127.0.0.1:9931/v1"
env_key = "LLAMA_API_KEY"Copiedwire_api can be left out: responses is the default and the only value Codex accepts. The ids openai, ollama and lmstudio are reserved, so the provider needs a name of its own.
Claude Code
Because llama-server serves the Anthropic Messages API itself, Claude Code can point at it directly, with no translating proxy such as LiteLLM in between. Anthropic says plainly that it does not support routing Claude Code to non-Claude models, so this is a setup you own. Check the route first:
curl -sS http://127.0.0.1:9931/v1/messages \
-H "x-api-key: $LLAMA_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{"model": "gpt-oss-20b", "max_tokens": 32, "messages": [{"role": "user", "content": "Say hi"}]}'CopiedThen start Claude Code from the same shell:
export ANTHROPIC_BASE_URL=http://127.0.0.1:9931
export ANTHROPIC_AUTH_TOKEN="$LLAMA_API_KEY"
export ANTHROPIC_DEFAULT_HAIKU_MODEL=gpt-oss-20b
export CLAUDE_CODE_MAX_CONTEXT_TOKENS=65536
claude --model gpt-oss-20bCopiedEach line has a reason, all from Anthropic’s gateway docs:
ANTHROPIC_AUTH_TOKENsends the key as a bearer token, which llama-server accepts, and takes precedence over a claude.ai login straight away. With no key on the server, set it to any string anyway, or Claude Code asks you to log in.ANTHROPIC_DEFAULT_HAIKU_MODELis the model Claude Code uses for background work; pointing it at the same name means every request asks for the model you serve.CLAUDE_CODE_MAX_CONTEXT_TOKENS: Claude Code assumes a 1M-token window for a model name it does not recognise, and for a name that does not start withclaude-this variable replaces that assumption, so it compacts before the slot is full. The auto-compact setting cannot do the same job here, because it will not go below 100,000 tokens.
If requests fail with a 400 naming “Extra inputs are not permitted” or an unknown field, Anthropic’s table gives CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 as the first thing to try. Remote Control stops working while ANTHROPIC_BASE_URL points anywhere but Anthropic. The Ollama route to the same goal, with its trade-offs, is in Claude Code with Ollama.
When it does not work
| What you see | Why | What to do |
|---|---|---|
Connection refused on port 8080 | The client expects the old default; the server is on 9931 | Point the client at 9931, or start the server with --port 8080 |
503 with "Loading model" | The model is still downloading or loading | Wait; journalctl -u llama-server -f shows progress |
401 "Invalid API Key" | Missing or wrong key | Send it as Authorization: Bearer or x-api-key; check LLAMA_API_KEY is set in the client’s shell |
couldn't bind HTTP server socket in the log | Something else holds the port, or the address in --host does not exist yet | sudo ss -ltnp | grep 9931; for a Tailscale address, see the boot-order fix above |
The server refuses to start with a security: line about server tools | --tools, --agent or MCP options on a non-loopback address with no key | Add a key, or bind to 127.0.0.1 |
The agent forgets earlier work, or long sessions end in errors | The agent’s context limit is larger than the slot the server gives it | Read n_ctx_slot in the startup log and set the agent’s limit to it |
-hf fails to download on a source build | Possibly built without libssl-dev, so without SSL support | Install it and rebuild |
If the goal is a model server you set up once and forget, the Ollama server guide covers the same job with Ollama, which manages the model files and the engine for you.