SabaKore

Run AI on a VPS / Install Ollama

How to install Ollama on a VPS and run a local LLM

These steps take you from a fresh Ubuntu 24.04 or 22.04 VPS to running a model with Ollama and using it from your own PC. It takes about 10 minutes, not counting the model download. First, choose a plan with enough memory for the model you want (how to choose a plan).

1Connect to the VPS and update it

After signing up and choosing Ubuntu as the OS, connect over SSH. The user name and IP address are shown in the provider's control panel.

ssh USER@SERVER_IP

Once connected, update packages and install the tools used below.

sudo apt update && sudo apt upgrade -y
sudo apt install -y curl zstd

If you have not yet set up SSH key authentication and a firewall, do that first.

2(Optional) Create swap as a safety net

A model that barely fits can briefly run out of memory and crash. With swap (disk space used in place of memory), it slows down instead of crashing. Disk is far slower than memory, so this does not fix a memory shortage. It is only a safety net. Check the Swap line of free -h to see if you already have 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

3Install Ollama

Run the official install script. To read it first, open the URL in your browser.

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

Ollama is registered as a service and starts automatically. It listens only inside the server (127.0.0.1, port 11434). Check that it is running:

ollama -v
systemctl status ollama

If you see active (running), it worked.

4Download and run a model

ollama run downloads and starts a model in one step. The first run downloads the model, which takes time depending on its size. Start with a small one.

ollama run llama3.2:3b

When the prompt appears, you can chat with it. Type /bye to quit. For other models, the plan finder shows the command for each one.

ollama list        # downloaded models and their disk usage
ollama ps          # models loaded now and their memory usage
ollama rm MODEL    # delete a model you no longer use

For programs, an HTTP API runs on the same port 11434. To try it from inside the server:

curl http://localhost:11434/api/generate -d '{
  "model": "llama3.2:3b",
  "prompt": "What is a VPS? Answer in one sentence.",
  "stream": false
}'

5Use it from your PC: SSH tunnel (recommended)

If only you use it, the safest way is to keep Ollama closed to the outside and connect from your PC through SSH. Keep this running on your PC, and port 11434 on your PC connects to Ollama on the VPS.

ssh -N -L 11434:localhost:11434 USER@SERVER_IP
Your PC  localhost:11434
   │  SSH tunnel (port 22, encrypted)
   ▼
VPS      Ollama on 127.0.0.1:11434 (not exposed)

Internet ──✕──> port 11434   (cannot reach it directly)

While it runs, apps and browsers on your PC can use http://localhost:11434. No port is opened on the server, so you add no new way in from the outside.

6If you connect directly from outside

Ollama has no authentication. If it is reachable from outside, anyone can run models on your server (using your CPU and memory; if abused, your account may be suspended). If you must connect directly, allow only your own IP address.

sudo systemctl edit ollama.service
# In the editor, add these two lines and save
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
# Apply
sudo systemctl daemon-reload
sudo systemctl restart ollama
sudo ufw allow from YOUR_IP to any port 11434 proto tcp

If your provider has its own firewall (packet filter), apply the same restriction there. For several users, put a reverse proxy with authentication, or a UI with login such as Open WebUI, in front of it.

7Troubleshooting

  • It stops with "Killed" or exits on its own: most likely the OS killed it for lack of memory. Long conversations or many simultaneous users need more memory for the conversation cache (KV cache) than the estimates on our model table. Check for a record with sudo dmesg | grep -i -E "out of memory|killed process". If there is one, use a smaller model or move to a plan with more memory.
  • The download fails partway: check free disk space with df -h. You need well more than the model size.
  • Commands do not respond: read the service log with journalctl -e -u ollama.
  • Replies are slow: on CPU only, larger models are slower. We do not measure speed, so we cannot give numbers. Switch to a smaller model and see whether it is usable.

8Updating and cleaning up

# Update Ollama: run the install script again
curl -fsSL https://ollama.com/install.sh | sh

# Stop it and disable autostart
sudo systemctl disable --now ollama

A VPS you no longer use keeps costing money until you cancel it. Delete model files with ollama rm.

FAQ

Does it work on a VPS without a GPU?

Yes. Ollama runs on CPU alone. Replies will be slower, and memory decides which models you can load. We do not measure speed, so we cannot say how many seconds it takes. Start with a small model and check for yourself whether it is usable.

What happens if there is not enough memory?

The model fails to load, or the OS kills the process while it is running. The screen only shows "Killed" with no reason. You can confirm the cause with dmesg or journalctl (see "Troubleshooting").

Can I expose it to the internet?

We do not recommend it. Ollama has no authentication, so anyone could run models on your server. If only you use it, connecting through an SSH tunnel is the safest option (step 5).

Compare VPS plans that fit each model →

The commands follow Ollama's official instructions. Behavior can change between versions, so if something does not work, also check the official Linux instructions.