Self-hosted LLM: running a language model on your own hardware

Updated

A self-hosted LLM is an open-weight language model running on a machine you control, served by a program such as Ollama or llama.cpp. On Linux you can have one answering questions within minutes: install the runtime, pull a model that fits your memory, and talk to it on localhost. The hard parts are memory, keeping the API off the open internet, and being honest about whether a paid API would serve you better.

At a glance

Item Ollama llama.cpp (llama command)
Install on Linux install.sh from ollama.com, or a manual tarball install.sh from llama.app, packages, or build from source
Runs as systemd service (ollama serve) llama serve in a terminal, or your own service
Default address 127.0.0.1:11434 127.0.0.1:9931
Built-in API auth None for the local API --api-key
Licence of the runtime MIT MIT
Release pace (checked 2026-12-05) Releases on 28 Nov and 4 Dec 2026, plus a pre-release on 5 Dec Numbered builds several times a day, plus versioned releases (v1.1.1 on 4 Dec 2026)

For the wider picture of self-hosted AI tools, start at the self-hosted AI hub.

When self-hosting an LLM is the wrong choice

Say it plainly before you buy hardware: for many people a paid API is cheaper and better.

  • Low or bursty use. A GPU you bought for a few prompts a day sits idle most of the time, and it still costs power. The LLM hosting cost guide walks through the numbers, and the self-hosting cost calculator lets you plug in your own.
  • You need the strongest models. The largest open models need data-center hardware. Ollama’s own page for gpt-oss says the 120b version fits on a single 80 GB GPU, which is not a home-server part.
  • You do not want an on-call job. A local model needs updates, monitoring and disk space.

Self-hosting makes sense when prompts must not leave your network, when you need it offline, when you run steady high volume, or when you want to experiment freely. The self-hosted AI vs ChatGPT comparison covers the trade-offs in detail.

How much memory a model needs

There is no single rule, so use the figures the projects publish for each model:

Model What the official page says
gemma4:e2b (Ollama) Ollama’s quickstart recommends 8 GB of available VRAM, or unified memory on a Mac
Gemma 4 E4B, 4-bit (llama.cpp) About 6 GB of memory with a 16k-token context, per the llama.app quickstart
gemma4:26b / gemma4:31b (Ollama) Download sizes listed at 16-19 GB and 19-20 GB
gpt-oss:20b (Ollama) Download listed at 14 GB; runs on systems with as little as 16 GB of memory
gpt-oss:120b (Ollama) Download listed at 65 GB; fits on a single 80 GB GPU

Sizes checked 2026-12-05 on ollama.com and llama.app.

Three things change the picture. A longer context window needs more memory. Ollama’s context-length page says the default depends on VRAM (4k tokens below 24 GiB, 32k up to 48 GiB, 256k above), but its FAQ still says 4,096 tokens, so check the CONTEXT column of ollama ps instead of assuming. The docs suggest at least 64,000 tokens for agents and coding tools, and parallel requests multiply the context. Set it with OLLAMA_CONTEXT_LENGTH. When a model does not fit in VRAM, Ollama can spill into system RAM, but answers slow down; ollama ps shows the split as CPU/GPU percentages. And llama.cpp adjusts unset options to fit your device memory by default.

On the GPU side, Ollama supports NVIDIA cards with compute capability 5.0 or newer and driver 550 or newer (570 or newer for compute capability 5.0 to 6.2), AMD cards through ROCm and Vulkan, and Apple GPUs through Metal. If you are putting together a machine for this, the home server build guide covers cases, power and storage.

Option 1: Ollama on Linux

What the install script does

Ollama’s Linux docs give a one-line install:

curl -fsSL https://ollama.com/install.sh | sh

Read what it does before you run it. The script, served from the latest GitHub release, uses sudo to:

  • download the Ollama package for your CPU architecture and unpack it, usually under /usr/local (it needs zstd for that, and tells you how to install it if missing);
  • create an ollama system user, add it to the render and video groups, and add your own user to the ollama group;
  • write /etc/systemd/system/ollama.service, then enable and start it;
  • look for a GPU. With an AMD card it downloads the extra ROCm package. With an NVIDIA card but no working driver, on Debian, Ubuntu, Fedora, RHEL, Rocky or Amazon Linux it adds NVIDIA’s CUDA repository and installs cuda-drivers plus kernel headers. With no GPU it warns that Ollama will run in CPU-only mode.

If you would rather not pipe a script into your shell, download it to a file and read it first, or use the documented manual install:

curl -fsSL https://ollama.com/download/ollama-linux-amd64.tar.zst \
    | sudo tar x -C /usr

The manual route then has you create the ollama user and a systemd unit yourself, as shown on the Linux docs page.

First run

Pull and chat with the model the quickstart uses:

ollama run gemma4:e2b

Type /bye to leave. Then test the API on the same machine:

curl http://localhost:11434/api/chat \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemma4:e2b",
    "messages": [
      {
        "role": "user",
        "content": "Say hello in one sentence."
      }
    ],
    "stream": false
  }'

The same server also offers OpenAI- and Anthropic-compatible endpoints under /v1/, so most clients only need their base URL changed. On Linux, models live in /usr/share/ollama/.ollama/models; set OLLAMA_MODELS to move them to a bigger disk.

Ollama also offers cloud models. If you want everything to stay local, set OLLAMA_NO_CLOUD=1 (or "disable_ollama_cloud": true in ~/.ollama/server.json) and restart.

Ollama in Docker

The Docker docs start the CPU-only container like this, with one change shown here: the docs publish -p 11434:11434, which Docker binds on all host addresses. Docker’s own documentation calls published ports “insecure by default”, so bind to loopback instead:

docker run -d -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollama
docker exec -it ollama ollama run llama3.2

For NVIDIA GPUs, install the NVIDIA Container Toolkit first and add --gpus=all, as the Docker page describes.

Option 2: llama.cpp

llama.cpp is the inference engine Ollama names as its backend. Its README now points to a one-line installer:

curl -LsSf https://llama.app/install.sh | sh

That script runs without sudo. It detects your CPU architecture and OS, asks Hugging Face for the latest build number, then on Linux probes for CUDA, ROCm, Vulkan and finally the CPU’s features, downloading small probe tools to do so. It fetches the matching prebuilt llama binary into ~/.llama-app, checks that it runs and reports the expected version, and copies it to ~/.local/bin/llama. If you prefer packages, the install docs list Homebrew, conda-forge, Nix and others, and the build guide covers compiling from source.

Start a server with a model from Hugging Face:

llama serve -hf ggml-org/gemma-4-e4b-it-GGUF:Q4_0

It listens on http://127.0.0.1:9931, serves a web chat at that address and an OpenAI-compatible API under /v1. Unlike Ollama’s local API, the server can require a key: start it with --api-key (or --api-key-file) and clients send Authorization: Bearer with that key. The server README also lists --ssl-key-file and --ssl-cert-file for TLS, though for anything outside your machine a reverse proxy is simpler.

Some examples, including the Docker commands in the server README, still set port 8080 explicitly, and the separate llama-server binary still exists. Check which port your setup actually uses before you write firewall or proxy rules.

Reaching your model from other machines safely

Never forward port 11434 or 9931 on your router, and never open it in a cloud firewall. Ollama binds 127.0.0.1:11434 by default, and the FAQ shows how to change that with OLLAMA_HOST, for example 0.0.0.0:11434. Do that only on a machine no one outside can reach. The local API takes requests with no key, so anyone who reaches it can run models, pull new ones and use your hardware.

Pick one of these instead:

SSH tunnel. Good for one person. From your laptop:

ssh -N -L 11434:localhost:11434 you@server.example.org

Your laptop’s localhost:11434 now reaches the server’s Ollama through SSH, and the server’s port stays closed.

VPN. Good for a household or small team. Put the server and clients on WireGuard or a similar VPN and allow the port only on the VPN interface. The llama.app site mentions Tailscale for reaching a model from your other devices.

Reverse proxy with TLS and a password. Needed only when a client cannot use a tunnel or VPN. Ollama’s FAQ shows an Nginx example, but it listens on plain port 80 with no authentication, so do not deploy it as written. Caddy fetches and renews TLS certificates automatically for a public domain. This combines Caddy’s documented basic_auth and reverse_proxy examples:

llm.example.org {
	basic_auth {
		alice CHANGE_ME
	}
	reverse_proxy localhost:11434 {
		header_up Host {upstream_hostport}
	}
}

Replace CHANGE_ME with a hash from caddy hash-password; Caddy does not accept plaintext passwords. Caddy versions before 2.8.0 call the directive basicauth. The header_up line sends the upstream address as the Host header, as Ollama’s proxy example does. Check that your client can send a username and password; if it can only send an API key, put llama.cpp’s --api-key behind the proxy or use the VPN route. For agents and automation that call the model, see self-hosted AI agents.

Updates and backups

Updates. On Linux, re-run the Ollama install script or re-download the tarball; on macOS and Windows the app downloads updates automatically. Pin a version with OLLAMA_VERSION if you need to. In Docker, pull the newer image and recreate the container; the ollama volume keeps your models. For llama.cpp, re-running the llama.app script says “Already up to date” when there is nothing new. Both projects release often, so check their release pages and keep the OS and GPU drivers patched too. If you exposed anything through Caddy, keep Caddy updated as well.

Backups. Models are large but can be downloaded again, so you rarely need to back them up. Back up what you cannot re-download: systemd overrides (systemctl edit ollama), any custom Modelfiles, your Caddyfile, and the data of the apps that use the model. llama.cpp keeps downloads in the standard Hugging Face cache, which can also be rebuilt.

Model licences differ

“Open” does not mean one licence. Check the licence of each model before you build on it:

  • Gemma 4: Google publishes it under the Apache License 2.0.
  • gpt-oss: Apache 2.0, per Ollama’s model page.
  • Llama 3.2 (used in Ollama’s Docker example): the Llama 3.2 Community License, which requires following Meta’s Acceptable Use Policy, displaying “Built with Llama” when you distribute it, and a separate licence from Meta for services above 700 million monthly active users.

The runtimes themselves, Ollama and llama.cpp, are both MIT-licensed. The model licence is the one that matters for what you may do with the output and with derived models.

Frequently asked questions

Can I run a self-hosted LLM without a GPU?
Yes. Ollama's install script falls back to CPU-only mode when it finds no NVIDIA or AMD GPU, and both Ollama and llama.cpp can keep a model in system RAM. Expect slower answers; Ollama's quickstart says responses may be slower when a model does not fit in VRAM.
How much VRAM do I need?
It depends on the model and the context window. Ollama's quickstart recommends 8 GB of available VRAM (or unified memory on a Mac) for gemma4:e2b. Ollama's gpt-oss page says the 20b model runs on systems with as little as 16 GB of memory and the 120b model fits on a single 80 GB GPU. Longer context windows need more memory on top.
Should I pick Ollama or llama.cpp?
Ollama is the easier start on Linux: one service, a model library and a simple CLI. llama.cpp is the engine underneath, with more knobs, a built-in web chat, and an API key option on its server. Both use the same GGUF model family and both listen on localhost by default.
Is it safe to set OLLAMA_HOST=0.0.0.0?
Only on a machine that is not reachable from the internet, or when the port is restricted to a VPN interface. Ollama's local API takes requests without an API key, so anyone who can reach the port can use your models. For remote use, prefer an SSH tunnel, a VPN, or a reverse proxy with TLS and authentication.
Does Ollama send my prompts to ollama.com?
Ollama's FAQ says it does not see your prompts when you run models locally. Cloud models are processed by Ollama's service. To turn the cloud features off entirely, set OLLAMA_NO_CLOUD=1 or disable_ollama_cloud in ~/.ollama/server.json and restart Ollama.

Sources, checked December 5, 2026

  1. Ollama repository and README
  2. Ollama docs: Linux (install, manual install, systemd, updating)
  3. Ollama docs: Quickstart (gemma4:e2b memory recommendation, local API)
  4. Ollama docs: Local FAQ (default bind 127.0.0.1:11434, OLLAMA_HOST, proxy, cloud opt-out, model storage)
  5. Ollama docs: Context length (defaults by VRAM)
  6. Ollama docs: Docker
  7. Ollama docs: Hardware support
  8. Ollama install script (served from the latest GitHub release)
  9. Ollama releases
  10. Ollama library: gemma4 tags and sizes
  11. Ollama library: gpt-oss (sizes, memory, Apache 2.0)
  12. llama.cpp repository and README
  13. llama.cpp docs: install pre-built versions
  14. llama.cpp server README (default host, --api-key, SSL options)
  15. llama.cpp releases
  16. llama.app docs: Installation
  17. llama.app install script
  18. llama.app docs: Quickstart (Gemma 4 E4B memory use)
  19. llama.app docs: Running a server
  20. llama.app docs: API server
  21. llama.app home page (reaching it over Tailscale)
  22. Google: Gemma 4 licence (Apache License 2.0)
  23. Meta: Llama 3.2 Community License Agreement
  24. Docker docs: Port publishing and mapping
  25. OpenBSD manual: ssh(1), -L and -N options
  26. Caddy docs: basic_auth directive
  27. Caddy docs: reverse_proxy directive
  28. Caddy docs: Automatic HTTPS

More in Self-hosted AI