How to Deploy Ollama and Local LLMs on a VPS in 2026

One-sentence verdict: you can run small language models on a $10–$30/month VPS with 8–16 GB RAM, but keep expectations realistic — CPU-only inference is slow, and anything above 7B parameters needs serious hardware.

Who This Guide Is For

If you need real-time chat with sub-second token streaming for end users, this setup is not the answer. You need GPU instances or managed inference APIs for that.

What Ollama Actually Needs

Ollama is a wrapper that makes running quantized LLMs simple. One command downloads and serves a model. The catch is hardware.

Minimum Requirements by Model Size

ModelParametersRAM needed (Q4 quantized)Recommended VPSTokens/sec (CPU-only)
Phi-3 Mini3.8B4 GB4 GB RAM / 2 vCPU8–12 t/s
Llama 3.2 3B3B3.5 GB4 GB RAM / 2 vCPU10–15 t/s
Mistral 7B7B6 GB8 GB RAM / 4 vCPU4–7 t/s
Llama 3.1 8B8B6.5 GB8 GB RAM / 4 vCPU3–6 t/s
Llama 3.1 70B70B42 GBNot feasible on budget VPS< 1 t/s

Rule of thumb: the model file in Q4_K_M quantization is roughly 60% of the parameter count in GB. Your VPS needs that plus 2–3 GB for the OS, Ollama runtime, and your application.

Provider Comparison for AI Workloads

ProviderBest plan for OllamaMonthly costRAM / vCPUWhy it worksCTA
HetznerCX32 or CX42€7–€158–16 GB / 4–8 vCPUBest price per GB RAM in EuropeStart with Hetzner →
ContaboVPS M or L$7–$138–16 GB / 4–6 vCPUCheapest raw RAM, slower CPUStart with Contabo →
DigitalOceanRegular 8 GB Droplet$488 GB / 4 vCPUEasy setup, premium pricingStart with DigitalOcean →
VultrHigh Frequency 8 GB$488 GB / 4 vCPUFast NVMe, many regionsStart with Vultr →
RackNerdSpecial 8 GB$30–$40/year8 GB / 4 vCPUExtreme budget (Black Friday deals)Check RackNerd deals →

Budget pick: Hetzner CX32 (8 GB RAM, 4 vCPU, ~€7.50/month) handles 7B models comfortably. If you only need 3B models, Contabo’s cheapest 8 GB plan or even a 4 GB Hetzner instance works.

Step-by-Step Deployment

1. Provision the Server

Choose Ubuntu 22.04 or 24.04 LTS. Minimum 8 GB RAM for 7B models.

# After SSH into your new VPS
sudo apt update && sudo apt upgrade -y
sudo apt install -y curl wget

2. Install Ollama

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

This installs the Ollama binary and sets up a systemd service. Verify:

ollama --version
systemctl status ollama

3. Pull a Model

Start with a small model to test:

# Lightweight and fast — good for testing
ollama pull phi3

# Better quality, needs 6+ GB free RAM
ollama pull llama3.1:8b-instruct-q4_K_M

4. Test Locally

ollama run phi3 "Explain what a VPS is in two sentences."

If this works without out-of-memory errors, your server can handle the model.

5. Expose the API (Optional)

Ollama serves an OpenAI-compatible API on port 11434 by default, but only on localhost.

To expose it safely:

# Edit the systemd service to listen on all interfaces
sudo systemctl edit ollama

# Add these lines:
# [Service]
# Environment="OLLAMA_HOST=0.0.0.0"

sudo systemctl restart ollama

Then protect it with a reverse proxy and authentication:

sudo apt install -y nginx apache2-utils

# Create a password file
sudo htpasswd -c /etc/nginx/.htpasswd llmuser

# Nginx config
sudo tee /etc/nginx/sites-available/ollama << 'EOF'
server {
    listen 443 ssl;
    server_name your-domain.com;

    ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;

    location / {
        auth_basic "LLM API";
        auth_basic_user_file /etc/nginx/.htpasswd;
        proxy_pass http://127.0.0.1:11434;
        proxy_set_header Host $host;
        proxy_read_timeout 300s;
    }
}
EOF

sudo ln -s /etc/nginx/sites-available/ollama /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

6. Connect from Your App

Use the OpenAI-compatible endpoint:

import openai

client = openai.OpenAI(
    base_url="https://your-domain.com/v1",
    api_key="not-needed-but-required-field",
)

response = client.chat.completions.create(
    model="llama3.1:8b-instruct-q4_K_M",
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)

Performance Tuning Tips

  1. Use quantized models. Q4_K_M gives the best speed/quality balance. Q5 is slightly better quality but 20% slower.
  2. Set num_ctx lower. Default context window is 2048 tokens. Reducing to 1024 speeds up inference for short tasks.
  3. Limit concurrent requests. Ollama queues requests by default. Two simultaneous users on a 7B model will cause timeouts.
  4. Add swap space. If your VPS has exactly enough RAM, a 4 GB swap file prevents OOM kills during model loading.
  5. Monitor with htop. Watch RSS memory during inference. If it touches 90% of total RAM, downgrade to a smaller model.
# Add 4 GB swap
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Risks and Honest Limitations

RiskRealityMitigation
Slow inference7B model on 4 vCPU = 3–7 tokens/second. A 500-word response takes 30–60 seconds.Use 3B models for speed-sensitive tasks
OOM crashesModel loading spikes RAM briefly above steady-state usageAdd swap, monitor, set limits
No GPU accelerationBudget VPS has no GPU. Inference is pure CPU.Accept the speed trade-off or rent GPU instances
Model qualitySmall quantized models hallucinate more than GPT-4 or ClaudeUse for low-stakes tasks: drafts, summaries, classification
Security exposureAn open Ollama port = anyone can use your serverAlways use auth + HTTPS, never expose port 11434 directly
Bandwidth spikesDownloading a 7B model is 4–5 GBPull models once, keep them on disk

When NOT to Use This Setup

Cost Comparison: Self-Hosted vs API

ApproachMonthly costSpeedPrivacyBest for
Ollama on Hetzner 8 GB~$83–7 t/sFull controlInternal tools, experiments
Ollama on Contabo 16 GB~$135–10 t/sFull controlRunning multiple models
OpenAI GPT-4o Mini API~$5–$50 (usage)50+ t/sData sent to OpenAIProduction apps with low volume
Groq (Llama 3.1 70B)Free tier / ~$1–$10200+ t/sData sent to GroqSpeed-critical, non-private tasks

Self-hosting makes sense when: (1) you need data to stay on your server, (2) you have low request volume, and (3) you can tolerate 5–30 second response times.

For most people running Ollama on a budget VPS:

Final Checklist


Last updated: June 2026. Prices and model performance change frequently. Verify current plans on provider websites before purchasing.