A one-command install, querying a model through the API, how much memory you need, and how to expose it safely - Ollama has no auth.
Ollama is a lightweight server for running language models on your own hardware. It installs with one command, exposes an HTTP API that is compatible with the OpenAI format, and works even on a plain VPS with no GPU - if you match the model to the amount of memory. Here is how to install Ollama on a server, query a model through the API, and, most importantly, how to expose it without handing your resources to the whole internet.
In short. Install with
curl -fsSL https://ollama.com/install.sh | sh; theollamaservice then listens on127.0.0.1:11434. Pull a model withollama pull; send requests to/api/generateor the OpenAI-compatible/v1/chat/completions. Memory rule: you need RAM of at least the model file size plus 1-2 GB. Ollama has no built-in auth - expose it only behind a reverse proxy with a password, an IP-scoped firewall, or an SSH tunnel.
Ollama runs GGUF-format models (Llama, Qwen, Gemma, Phi, Mistral and others), manages loading them into memory and unloading them, and serves a single HTTP API. On your own server this matters when:
The main constraint is RAM. The whole model loads into memory (or into VRAM if there is a GPU). You need: the model file size + 1-2 GB for context and bookkeeping.
Model | Size | Minimum RAM | Good for |
|---|---|---|---|
| ~1.3 GB | 3 GB | simple tasks, rough drafts, classification |
| ~2 GB | 4 GB | short answers, data extraction |
| ~4.7-5 GB | 8 GB | substantive answers, summarizing, code |
| ~275 MB | 2 GB | embeddings for document search |
About speed. With no GPU, inference runs on the CPU. On a modern VPS core, 1-3B models produce a few tokens per second - fine for scripts and background processing, already slow for a live chat. 7-8B models on CPU are single-digit tokens per second, usable for batch jobs, not for interactive use. A GPU changes this by an order of magnitude, but a VPS with a GPU costs noticeably more.
Log in to the server over SSH as root (or via sudo) and run the official installer:
curl -fsSL https://ollama.com/install.sh | sh
The script downloads the binary, creates a system user ollama and a service ollama.service that starts now and on boot. If the server has a supported NVIDIA or AMD GPU, the installer picks it up; otherwise it runs in CPU mode.
Check:
ollama --version
systemctl status ollama --no-pager
By default the service listens only on 127.0.0.1:11434 - it is not reachable from outside yet, which is correct (see step 4).
Pull a model that fits your memory. Start with a light one:
ollama pull llama3.2:1b
List what is already downloaded:
ollama list
A quick terminal test (exit with /bye):
ollama run llama3.2:1b "In one sentence: what is a reverse proxy?"
What is currently in memory and how much it takes:
ollama ps
Ollama serves an HTTP API on the same port 11434. A single request:
curl http://localhost:11434/api/generate -d '{
"model": "llama3.2:1b",
"prompt": "List three upsides of running an LLM on your own VPS",
"stream": false
}'
The reply has a response field with the text. "stream": false returns the answer whole; without it Ollama sends a stream of JSON chunks.
For a conversation with history use the /api/chat endpoint with a messages array. For ready-made clients (the OpenAI SDK, LangChain, n8n) there is an OpenAI-compatible endpoint:
curl http://localhost:11434/v1/chat/completions -d '{
"model": "llama3.2:1b",
"messages": [{"role": "user", "content": "Hello"}]
}'
In the OpenAI SDK it is enough to set a base_url like http://YOUR_SERVER:11434/v1 and any non-empty key.
Ollama has no auth. Anyone who can reach port 11434 can run your models and load the server. So simply "opening the port to the world" is a bad option. Pick one of three.
Keep Ollama on localhost and forward the port from the client:
ssh -N -L 11434:localhost:11434 user@YOUR_SERVER
Requests to http://localhost:11434 from your machine now reach Ollama on the server. The simplest option if only you need access.
Put a web server in front of Ollama to add HTTPS and a password check. In Caddy it is a few lines in the Caddyfile:
llm.example.com {
basic_auth {
apiuser $2a$14$...password_hash...
}
reverse_proxy 127.0.0.1:11434
}
Generate the password hash with caddy hash-password. How to install Caddy and get a certificate - see Caddy: automatic HTTPS in 5 minutes.
If Ollama must listen externally, open the port to your address only. First let the service listen beyond localhost - systemctl edit ollama, add:
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
systemctl daemon-reload && systemctl restart ollama
And immediately restrict access with the firewall:
ufw allow from YOUR_IP to any port 11434 proto tcp
ufw deny 11434
Options are set as environment variables via systemctl edit ollama:
OLLAMA_MODELS - where to store models (default /usr/share/ollama/.ollama/models); move it to a larger disk if you have many.OLLAMA_KEEP_ALIVE - how long to keep a model in memory after a request (default 5m); -1 is forever, 0 unloads immediately.OLLAMA_NUM_PARALLEL - how many requests to handle at once.OLLAMA_MAX_LOADED_MODELS - how many different models to keep in memory together.llama3.2:1b or gemma2:2b, fast and cheap on memory.qwen2.5:7b or llama3.1:8b, if you have 8 GB of RAM.nomic-embed-text for embeddings plus a small generative model for the answer.ollama.com/library; each model has variants by parameter count and by quantization (q4, q8) - lower quantization means less memory and less quality.model "X" not found. The model is not downloaded. ollama pull X.127.0.0.1. Either a tunnel, or OLLAMA_HOST=0.0.0.0 plus a proxy or firewall (step 4).OLLAMA_KEEP_ALIVE.