What You Need
- A VPS with at least 4 GB RAM (8 GB recommended for 7B models)
- Ubuntu 22.04 or 24.04
- Basic SSH access
A quick reference for model sizing:
| RAM | Model | Speed |
|---|---|---|
| 4 GB | 3B (Q4) | 10–20 tok/s |
| 8 GB | 7B (Q4) | 5–10 tok/s |
| 16 GB | 13B (Q4) | 3–6 tok/s |
The Standard plan on NoctHost (2 vCPU, 4 GB RAM) handles 3B models comfortably. For 7B models, use the Pro plan (4 vCPU, 8 GB RAM).
Step 1: Install Ollama
apt update && apt upgrade -y
curl -fsSL https://ollama.com/install.sh | shVerify the service is running:
systemctl status ollamaStep 2: Pull a Model
For 8 GB RAM, Llama 3.3 8B is the recommended starting point:
ollama pull llama3.1:8bFor 4 GB RAM, use a 3B model:
ollama pull llama3.2:3bTest it interactively:
ollama run llama3.1:8bType a prompt and press Enter. Use /bye to exit.
Step 3: Configure for External Access
By default Ollama only listens on localhost. To expose it to Docker containers or a reverse proxy:
mkdir -p /etc/systemd/system/ollama.service.d
nano /etc/systemd/system/ollama.service.d/override.conf[Service]
Environment="OLLAMA_HOST=0.0.0.0"
Environment="OLLAMA_NUM_PARALLEL=1"
Environment="OLLAMA_MAX_LOADED_MODELS=1"systemctl daemon-reload
systemctl restart ollamaLock down the port with a firewall — never expose Ollama directly to the internet:
ufw allow from 172.16.0.0/12 to any port 11434
ufw deny 11434Step 4: Test the API
curl -X POST http://localhost:11434/api/generate \
-H "Content-Type: application/json" \
-d '{
"model": "llama3.1:8b",
"prompt": "Explain Docker in one paragraph.",
"stream": false
}'Ollama also exposes an OpenAI-compatible endpoint at /v1/chat/completions — drop-in compatible with any SDK that supports OpenAI's API.
Step 5: Set Ollama to Start on Boot
The install script creates a systemd service automatically. Verify it's enabled:
systemctl enable ollamaPerformance Tips
CPU inference is memory-bound. The entire model must fit in RAM or performance drops severely. A few things that help:
- Use Q4_K_M quantization — it preserves most model quality while cutting memory by 40–50%
- Keep
OLLAMA_NUM_PARALLEL=1on low-RAM servers - Monitor memory with
free -hbefore pulling large models