Skip to content

How to Deploy Ollama on a VPS

Updated Sep 2026

verified on Ubuntu 26.04 · Aug 2026
We earn commissions when you shop through the links below. Full disclosure →

Self-host Ollama on your own VPS — run open-source LLMs locally with GPU acceleration, an OpenAI-compatible API, and zero per-token costs.

Before you start
  • A VPS with 8+ GB RAM (16 GB recommended for 7B models)
  • A fresh Ubuntu 26.04 server with root/sudo SSH access
  • Optional: NVIDIA GPU for acceleration (CPU-only works for smaller models)
Need a box for this guide? Kamatera's free tier lets you spin one up now.Start free on Kamatera → (opens in new tab)

What Ollama is

Ollama is a lightweight, open-source tool for running large language models locally. It's like Docker for LLMs — you pull model weights with a simple command, and Ollama serves them through an OpenAI-compatible API. No API keys, no per-token billing, no data leaving your server.

The appeal is straightforward: cost and privacy. Commercial AI APIs charge per token, and a busy application can burn through credits fast. A VPS running Ollama costs the same whether you process a hundred requests a day or ten thousand. Your prompts and completions never leave your infrastructure, which matters when you're building tools that handle sensitive data or when you simply don't want your prompts training someone else's model.

Ollama supports hundreds of models — Llama 3, Mistral, Gemma, Phi, Qwen, and more — and downloads them on demand. The API is wire-compatible with OpenAI's, so most tools that work with ChatGPT can point at your Ollama instance with minimal changes.

Server sizing — RAM is the bottleneck

LLM inference is memory-bound. The model weights must fit in RAM (or VRAM) to run at all, and once they fit, more RAM means more room for context and concurrent requests.

CPU-only sizing:

  • 8 GB RAM — runs small models (3B parameters) comfortably, 7B models with tight context
  • 16 GB RAM — the sweet spot for 7B models with reasonable context length
  • 32 GB RAM — 13B models, or 7B models with large context windows
  • 64+ GB RAM — 30B+ models, or serving multiple users concurrently

GPU acceleration: If your VPS has an NVIDIA GPU, Ollama can use CUDA for dramatically faster inference. The model still loads into GPU VRAM, so the same sizing logic applies — a 7B model needs ~6 GB VRAM in FP16, ~4 GB in quantized format. GPU inference is 5-10x faster than CPU for tokens/second.

A 4 vCPU / 8 GB VPS is the minimum for CPU-only small models. For serious 7B+ usage, you need at least 16 GB RAM — a 4 vCPU / 8 GB box won't cut it; look at 8 vCPU / 16 GB or a GPU-equipped instance.

Prepare the server

Start from a fresh Ubuntu 24.04 or 26.04 server. Update and create a non-root user:

apt update && apt upgrade -y
adduser deploy
usermod -aG sudo deploy

Lock down the firewall:

ufw allow OpenSSH
ufw allow 80
ufw allow 443
ufw enable

Install Docker (Ollama runs in a container):

curl -fsSL https://get.docker.com | sh
usermod -aG docker deploy

Log out and back in as deploy so the docker group takes effect.

Where to host itaffiliate disclosure
Hetzner Cloudrun it on
2 vCPU · 4 GB RAM · 80 GB SSD · $23.59/mo
Get Hetzner Cloud (opens in new tab)
Kamaterafree trial
1 vCPU · 1 GB RAM · 20 GB SSD · $4.00/mo
Start free on Kamatera → (opens in new tab)
DigitalOceanalso works on
1 vCPU · 1 GB RAM · 25 GB SSD · $6.00/mo
Deploy on DigitalOcean → (opens in new tab)

Paid link — we earn a commission if you shop through it.

Install Ollama

The simplest path is the official Docker image. Create a working directory:

mkdir ~/ollama && cd ~/ollama

Create a compose file:

services:
  ollama:
    image: ollama/ollama:latest
    restart: unless-stopped
    ports:
      - "127.0.0.1:11434:11434"
    volumes:
      - ollama_data:/root/.ollama
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]  # comment out if no GPU

volumes:
  ollama_data:

Start it:

docker compose up -d

Ollama listens on port 11434 by default. The 127.0.0.1 bind keeps it private — a reverse proxy will handle public HTTPS access.

GPU support

If you have an NVIDIA GPU, install the NVIDIA Container Toolkit first:

curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | \
  gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
  sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
  tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
apt update
apt install -y nvidia-container-toolkit
nvidia-ctk runtime configure --runtime=docker
systemctl restart docker

Without a GPU, just remove the deploy.resources section from the compose file — Ollama falls back to CPU inference automatically.

Pull your first model

Pull a model and test it:

docker exec -it ollama ollama pull llama3.2
docker exec -it ollama ollama run llama3.2

That downloads the model weights (a few GB for 3B/7B variants) and drops you into an interactive chat. Type your message, press Enter, and watch it generate. /bye exits.

To pull a larger model later:

docker exec -it ollama ollama pull llama3.1:8b

The API is available immediately — no restart needed. Test it:

curl http://localhost:11434/api/generate -d '{
  "model": "llama3.2",
  "prompt": "What is the capital of France?"
}'

HTTPS + domain

Ollama's API should not face the internet without TLS. Point a reverse proxy at 127.0.0.1:11434 and terminate HTTPS on 443.

The simplest path is Automatic HTTPS with Caddy. Point an A record for your hostname (say ai.example.com) at the server's public IP, then have Caddy reverse-proxy that hostname to 127.0.0.1:11434. Caddy handles certificate issuance and renewal automatically.

If you're using the Caddy container approach from that guide, put Ollama and Caddy in the same compose file and proxy to the Ollama service name:

reverse_proxy ollama:11434

Using the API

Once HTTPS is up, point any OpenAI-compatible client at your endpoint. Most tools just need two values:

  • Base URL: https://ai.example.com/v1
  • Model: any model you've pulled (e.g., llama3.2)

Examples with curl:

# Chat completion (OpenAI-compatible)
curl https://ai.example.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama3.2",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'

# List available models
curl https://ai.example.com/v1/models

Tools like Open WebUI, LibreChat, and AnythingLLM can all point at this endpoint. If you're building your own app, the OpenAI SDK works with Ollama by changing the base URL — no code changes needed in most cases.

Backups

Ollama's state is small — just the model weights in the /root/.ollama volume. The weights themselves are re-downloadable, so you don't strictly need to back them up. What matters is your configuration and any custom Modelfiles you've created.

If you've customized models (system prompts, parameters, Modelfiles), back up the data volume:

docker compose exec ollama tar czf - /root/.ollama > ollama-config-$(date +%F).tar.gz

For a more complete backup including all downloaded models:

docker run --rm -v ollama_data:/data -v $(pwd):/backup alpine \
  tar czf /backup/ollama-full-$(date +%F).tar.gz -C /data .

This is a one-time cost — models don't change once downloaded, so you only need to back up when you add or modify something.

Upgrades

Pull the newer image and recreate:

docker compose pull
docker compose up -d

Ollama updates are usually non-breaking — the API is stable and model formats are backward-compatible. Check the Ollama blog for any notable changes.

Scaling for production

For heavier usage, consider these additions:

Separate model storage: Mount a larger disk for models if your root volume is small:

volumes:
  - /mnt/models:/root/.ollama

Multiple instances: Run separate Ollama containers for different model sizes or use cases, each on a different port.

Load balancing: For high-concurrency setups, put multiple Ollama instances behind a load balancer. Ollama handles one request per model at a time, so multiple instances means more parallel requests.

Nginx reverse proxy: For finer control than Caddy, use Nginx with rate limiting and caching. See the Next.js deployment guide for Nginx configuration patterns.

Troubleshooting

Model download fails or hangs. Check your disk space (df -h) — 7B models are 4-8 GB. Also check that you can reach ollama.com from the server (curl -I https://ollama.com).

Out of memory during inference. The model is too large for your RAM. Use a smaller model or a more aggressive quantization (e.g., q4_0 instead of q8_0). Check docker logs ollama for memory errors.

GPU not detected. Verify the NVIDIA Container Toolkit is installed and Docker can see the GPU: docker run --rm --gpus all nvidia/cuda:12.0-base nvidia-smi. If that fails, re-run the toolkit installation above.

Slow responses on CPU. This is expected — CPU inference is 5-10x slower than GPU. For better performance, use a smaller model or add a GPU. The tokens/second metric in the response tells you the actual throughput.

API returns "model not found." The model name must match exactly what you pulled. Check available models with curl http://localhost:11434/api/tags.

Verification + next steps

You're done when you can: pull a model, run it interactively, make API calls over HTTPS on your domain, and get coherent responses. The API should work with any OpenAI-compatible client.

From here, pair Ollama with Open WebUI for a ChatGPT-style browser interface, or integrate it into your applications via the API. For document-based AI workflows, AnythingLLM combines Ollama with a document management system. An 8 vCPU / 16 GB box is the right tier for 7B models; a GPU instance is the step up. See Best VPS for AI & ML Workloads for the ranked picks.

Next steps

How to self-host Ollama →More self-hosted ai chat interfaces tools →Best VPS for Ollama →Automatic HTTPS with Caddy →Run Claude Code with Ollama on Your Own VPS →Deploy Coolify on a VPS →How to Deploy Actual Budget on a VPS →How to Deploy AnythingLLM on a VPS →How to Deploy Appwrite on a VPS →How to Deploy Audiobookshelf on a VPS →How to Deploy Authelia on a VPS →How to Deploy authentik on a VPS →How to Deploy Baserow on a VPS →How to Deploy Beszel on a VPS →How to Deploy Bitwarden on a VPS →How to Deploy BookStack on a VPS →How to Deploy CapRover on a VPS →How to Deploy Checkmate on a VPS →How to Deploy Directus on a VPS →How to Deploy docker-mailserver on a VPS →How to Deploy Docmost on a VPS →How to Deploy Dokku on a VPS →How to Deploy Dokploy on a VPS →How to Deploy Firefly III on a VPS →How to Deploy Forgejo on a VPS →How to Deploy Gatus on a VPS →How to Deploy Ghostfolio on a VPS →How to Deploy Gitea on a VPS →How to Deploy GitLab on a VPS →How to Deploy GlitchTip on a VPS →How to Deploy Grafana on a VPS →How to Deploy Graylog on a VPS →How to Deploy Headscale on a VPS →How to Deploy Healthchecks on a VPS →How to Deploy Home Assistant on a VPS →How to Deploy Immich on a VPS →How to Deploy Jan on a VPS →How to Deploy Jellyfin on a VPS →How to Deploy Karakeep on a VPS →How to Deploy Keycloak on a VPS →How to Deploy Leantime on a VPS →How to Deploy LibreChat on a VPS →How to Deploy Linkwarden on a VPS →How to Deploy LocalAI on a VPS →How to Deploy Mailcow on a VPS →How to Deploy Mailu on a VPS →How to Deploy Matomo on a VPS →How to Deploy Mattermost on a VPS →How to Deploy Meilisearch on a VPS →How to Deploy Memos on a VPS →How to Deploy n8n on a VPS →How to Deploy Navidrome on a VPS →How to Deploy NetBird on a VPS →How to Deploy Netdata on a VPS →How to Deploy Nextcloud on a VPS →How to Deploy Next.js to a VPS →How to Deploy Nginx Proxy Manager on a VPS →How to Deploy NocoDB on a VPS →How to Deploy ntfy on a VPS →How to Deploy Open WebUI on a VPS →How to Deploy OpenHands on a VPS →How to Deploy OpenObserve on a VPS →How to Deploy OpenProject on a VPS →How to Deploy Outline on a VPS →How to Deploy Pangolin on a VPS →How to Deploy Paperless-ngx on a VPS →How to Deploy Passbolt on a VPS →How to Deploy Plane on a VPS →How to Deploy Plausible Analytics on a VPS →How to Deploy Pocket ID on a VPS →How to Deploy PocketBase on a VPS →How to Deploy Prometheus on a VPS →How to Deploy Psono on a VPS →How to Deploy Radarr on a VPS →How to Deploy Rocket.Chat on a VPS →How to Deploy SigNoz on a VPS →How to Deploy Sonarr on a VPS →How to Deploy Stalwart on a VPS →How to Deploy Stirling-PDF on a VPS →How to Deploy Supabase on a VPS →How to Deploy Synapse on a VPS →How to Deploy Taiga on a VPS →How to Deploy TeamPass on a VPS →How to Deploy Tinyauth on a VPS →How to Deploy Traefik on a VPS →How to Deploy Trilium on a VPS →How to Deploy Twenty CRM on a VPS →How to Deploy Umami on a VPS →How to Deploy Uptime Kuma on a VPS →How to Deploy Vaultwarden on a VPS →How to Deploy Vikunja on a VPS →How to Deploy wg-easy on a VPS →How to Deploy Wiki.js on a VPS →How to Deploy Zabbix on a VPS →How to Deploy Zitadel on a VPS →How to Deploy Zulip on a VPS →Docker & Compose on Ubuntu 26.04 →Building AI Workflows with n8n →Install Open WebUI with Ollama →Adding AI-Powered Insights to Plausible Analytics →Building AI-Powered Apps with Supabase and pgvector →

We use analytics cookies (Google Analytics, PostHog) to see which guides are useful. No ad networks, no cross-site tracking. See our privacy policy.