🤖
VPS

Ollama is a tool that makes it simple for system administrators and developers to download and run open-source Large Language Models (LLMs) on their own servers. Unlike cloud-based APIs from OpenAI or Anthropic where you pay per token, Ollama lets you host models locally—whether on a personal machine or a VPS—giving you complete control and no API billing.

In short: Ollama enables you to run LLMs like Llama 3 on your VPS without per-token API fees. However, LLMs are CPU and RAM-intensive, and most affordable VPS plans lack GPUs, so only smaller quantized models (7B–8B parameters in Q4 format) will run at usable speeds on CPU. Larger models will be painfully slow.

What Is Ollama and Why Use It?

Ollama is an open-source project that simplifies downloading and running LLMs on your own hardware—laptops, desktops, or servers. It handles model downloads, memory management, and model loading/execution automatically through an intuitive command-line interface.

Developers and operations teams typically self-host LLMs for three main reasons:

Hardware Reality: What Your VPS Can Actually Handle

Large Language Models are resource hogs. They demand massive amounts of RAM and CPU (or GPU) compute. It is critical to understand this before expecting smooth performance.

Warning: Most affordable VPS plans lack GPUs (graphics processors). LLMs will run on CPU alone, but very slowly. If you have a higher budget, a VPS with a GPU (NVIDIA RTX or better) will be orders of magnitude faster, but the cost jumps significantly.

Different model sizes have different requirements:

Model Size Quantized Size (Q4) Minimum RAM Speed (CPU) Recommendation
7B parameters ~4–5 GB 8 GB Slow (5–10 tokens/sec) Usable with patience
13B parameters ~8–9 GB 16 GB Very slow (1–2 tokens/sec) Not recommended for CPU
70B parameters 40+ GB 64+ GB Unusable without GPU Requires dedicated GPU machine

For a CPU-only VPS, we recommend using 7B-parameter models (like Llama 3.1 7B, Mistral 7B, or Phi-3) quantized at Q4 level. These use about 4–5 GB of disk space and 8–16 GB of total RAM—achievable on most moderately-sized VPS plans.

Tip: If you want faster responses, use an even smaller model like Phi-3 (3.8B) or Mistral (7B) instead of pushing Llama 3 70B, which will crawl on a CPU.

Prerequisites

Installing Ollama on Ubuntu

Ollama provides an official installation script. Follow these steps:

  1. SSH into your VPS:
ssh root@your-vps-ip
  1. Download and run the official install script:
curl -fsSL https://ollama.ai/install.sh | sh

This script installs the Ollama binary, required dependencies, and a systemd service automatically.

  1. Verify Ollama is running:
systemctl status ollama

Look for "active (running)". If you see that, installation succeeded. Ollama binds to localhost:11434 by default.

  1. Test connectivity:
ollama list

This shows installed models (will be empty on a fresh install).

Downloading and Running Your First Model

Let's download Llama 3 7B (stable and well-regarded):

  1. Pull the model:
ollama pull llama3

This downloads the Llama 3 8B model (~4.7 GB) from Ollama's repository. Be patient—do not interrupt the download.

  1. Run the model interactively:
ollama run llama3

When you see the > prompt, try typing a question:

> What is machine learning?

The model will generate a response, which may take a moment on CPU. That's normal.

  1. Exit the chat:
> /bye

Or press Ctrl+D.

Other popular models to try:

Using the REST API

Ollama exposes a REST API on localhost:11434, letting you send requests programmatically instead of using the interactive shell.

Here are basic curl examples:

  1. Simple generation request:
curl -X POST http://localhost:11434/api/generate \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama3",
    "prompt": "Explain quantum computing in simple terms",
    "stream": false
  }'

Setting "stream": false tells the API to wait for the full response before returning it.

  1. Using streaming (progressive output):
curl -X POST http://localhost:11434/api/generate \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama3",
    "prompt": "What is the capital of Thailand?",
    "stream": true
  }'

With "stream": true, the API sends back the response word-by-word as the model generates it, like ChatGPT's streaming interface.

The response is JSON:

{
  "model": "llama3",
  "created_at": "2024-01-15T10:30:00Z",
  "response": "The capital of Thailand is Bangkok...",
  "done": true
}

Building a Simple Chat Script

Here's a minimal Python script to interact with Ollama:

#!/usr/bin/env python3

import requests
import json

def chat_with_ollama(prompt, model="llama3"):
    url = "http://localhost:11434/api/generate"
    payload = {
        "model": model,
        "prompt": prompt,
        "stream": False
    }
    response = requests.post(url, json=payload)
    data = response.json()
    return data.get("response", "No response")

if __name__ == "__main__":
    user_input = input("You: ")
    response = chat_with_ollama(user_input)
    print(f"Ollama: {response}")

Usage:

python3 chat.py
You: How do I configure a firewall on Linux?
Ollama: To configure a firewall on Linux...

Security Considerations

⚠️ Critical: By default, Ollama listens only on localhost:11434, meaning only processes on the same server can reach it. This is secure and appropriate for local use.

Never expose port 11434 to the public internet without additional security layers. Doing so opens your server to:

If you need to expose Ollama to other servers, use an HTTPS reverse proxy (like Nginx) with authentication:

server {
    listen 443 ssl http2;
    server_name ollama.example.com;
    
    ssl_certificate /etc/ssl/certs/your-cert.crt;
    ssl_certificate_key /etc/ssl/private/your-key.key;
    
    auth_basic "Ollama API";
    auth_basic_user_file /etc/nginx/.ollama_auth;
    
    location / {
        proxy_pass http://localhost:11434;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_buffering off;
    }
}

This approach: 1) closes port 11434 from the internet, 2) opens port 443 (HTTPS) with an SSL certificate, and 3) adds HTTP Basic Auth so only authorized users can access the API.

Running Ollama as a Persistent Service

The installation script already created a systemd unit for Ollama. Here's how to manage it:

  1. View the systemd unit file:
cat /etc/systemd/system/ollama.service

You should see something like:

[Unit]
Description=Ollama Service
After=network-online.target

[Service]
ExecStart=/usr/bin/ollama serve
User=ollama
Group=ollama
Restart=on-failure
RestartSec=5s
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=default.target
  1. Enable Ollama to start automatically at boot:
systemctl enable ollama
  1. Restart the Ollama service:
systemctl restart ollama
  1. Monitor logs in real-time:
journalctl -u ollama -f

The -f flag streams logs as they appear.

Summary

Ollama dramatically simplifies running open-source LLMs on your own infrastructure. You don't need expensive GPUs (though they help) or reliance on third-party APIs.

Key takeaways:

Frequently Asked Questions

Should I use Ollama or LM Studio or something else?

Ollama comes with a built-in REST API server, making automation straightforward, and has a large model library. LM Studio is better for GUI-based desktop use. For a VPS, Ollama is the superior choice.

Which model is fastest on CPU?

Phi-3 (3.8B) is fastest, followed by Mistral 7B. Llama 3 7B is slightly slower but still usable. For 70B models, you absolutely need a GPU.

Can I run multiple models at once?

You can, but Ollama loads models into RAM sequentially. Running multiple large models simultaneously will exhaust RAM quickly. A model switching controller is a better approach for production.

What VPS specs do I need?

A minimum of 16 GB RAM and 4–8 vCPUs is ideal, costing roughly $10–30/month. While 8 GB might work, 16 GB offers a good balance of affordability and performance.

Start Your AsiaGB VPS Today

AsiaGB VPS runs on SSD storage across every plan, with Thailand or Singapore datacenter options and full root access from day one — starting at 500 THB/month (Linux), backed by a Thai support team.

See VPS Plans

View all affordable VPS Thailand plans →