Tutorials  /  Ubuntu

Install Ollama on Ubuntu 24.04 and Run It as a Service

LLudwig · August 2026 ·9 min read ·Ubuntu, Tutorial

Ollama serves local language models through a single HTTP API on port 11434. The official install script already ships a systemd unit, but its defaults bind to localhost only and keep every model under /usr/share/ollama, which is rarely the right place on a server with a separate data volume. This tutorial covers the installation on Ubuntu 24.04, the service configuration through a drop-in file, and the verification steps.

What is Ollama?

Ollama is a self-hosted runtime that downloads and serves open-weight language models such as Llama 3.2, Mistral or Qwen behind an HTTP API on 127.0.0.1:11434, including an OpenAI-compatible endpoint under /v1.

Models are distributed as quantized GGUF blobs and addressed by name and tag, for example llama3.2:3b. The server loads a model into RAM or VRAM on the first request, keeps it resident for five minutes by default, and unloads it afterwards. That behaviour is configurable, and it is the main reason the service should run as a long-lived daemon rather than being started per session.

Prerequisites

  • Ubuntu 24.04 LTS (Server or Desktop), architecture x86_64 or arm64
  • A user account with sudo rights
  • Outbound HTTPS access to ollama.com and registry.ollama.ai
  • At least 8 GB RAM for 7B/8B models in 4-bit quantization, 16 GB for comfortable headroom
  • Roughly 5 GB free disk space per model
  • Optional: an NVIDIA GPU with a working driver, verified through nvidia-smi

CPU-only inference works, it is simply slower. A 3B model on four modern vCPUs produces a few tokens per second, which is enough for testing and for low-volume internal tools. If you want to size the machine to the model instead of the other way round, run the setup on a scalable Cloud-VPS where vCPU and RAM can be adjusted later.

Install Ollama on Ubuntu 24.04

Update the package index and install the two packages the installer needs:

Console
$ sudo apt update
$ sudo apt install -y curl ca-certificates

Run the official install script:

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

The script performs four actions:

  1. Downloads the release tarball for your architecture and unpacks the binary to /usr/local/bin/ollama.
  2. Creates the system user and group ollama with the home directory /usr/share/ollama.
  3. Writes the unit file /etc/systemd/system/ollama.service.
  4. Runs systemctl enable --now ollama.

If your policy forbids piping a remote script into a shell, install manually. Inspect the tarball first, then extract it:

Console
$ curl -fsSL -o /tmp/ollama-linux-amd64.tgz https://ollama.com/download/ollama-linux-amd64.tgz
$ sudo tar -C /usr -xzf /tmp/ollama-linux-amd64.tgz
$ sudo useradd -r -s /bin/false -U -m -d /usr/share/ollama ollama

With the manual route you write the unit file yourself, using the same content shown in the next section. For AMD GPUs, add the ROCm payload from ollama-linux-amd64-rocm.tgz on top of the base tarball.

Confirm the binary is in place:

Console
$ ollama --version
ollama version is 0.12.3
VM

Matching infrastructure at centron

No hardware needed to follow along: ccloud³ VMs with full root access, billed by the hour and ready in seconds. Rent a cloud server →

How does the Ollama systemd service work?

The Ollama systemd service runs /usr/local/bin/ollama serve as the unprivileged system user ollama, listens on 127.0.0.1:11434 by default, and loads model weights from /usr/share/ollama/.ollama/models on demand.

The CLI is a thin client. When you type ollama run, the command talks to the same HTTP API that any other client would use, so a running service and an interactive session share one loaded model instead of allocating memory twice.

graph TD
    A["ollama CLI"] --> C["HTTP API 127.0.0.1:11434"]
    B["Application / curl / OpenAI SDK"] --> C
    C --> D["systemd unit ollama.service"]
    D --> E["ollama serve process, user ollama"]
    E --> F["Model store /usr/share/ollama/.ollama/models"]
    E --> G["CPU or GPU inference"]

This is the unit the installer writes:

ini
[Unit]
Description=Ollama Service
After=network-online.target
[Service]
ExecStart=/usr/local/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
[Install]
WantedBy=multi-user.target

Do not edit this file directly. The next installer run overwrites it.

Configure the service with a drop-in

Use systemctl edit to create an override that survives upgrades:

Console
$ sudo systemctl edit ollama.service

Add the following block between the marker comments. It moves the model store to /var/lib/ollama/models, keeps models loaded for 30 minutes and allows two concurrent requests per model:

ini
[Service]
Environment="OLLAMA_MODELS=/var/lib/ollama/models"
Environment="OLLAMA_KEEP_ALIVE=30m"
Environment="OLLAMA_NUM_PARALLEL=2"
Environment="OLLAMA_MAX_LOADED_MODELS=1"

The most relevant variables:

Variable Default Purpose
OLLAMA_HOST 127.0.0.1:11434 Listen address and port
OLLAMA_MODELS ~/.ollama/models Directory for model blobs
OLLAMA_KEEP_ALIVE 5m How long a model stays in memory
OLLAMA_NUM_PARALLEL auto Concurrent requests per model
OLLAMA_MAX_LOADED_MODELS auto Models resident at the same time
OLLAMA_CONTEXT_LENGTH 4096 Default context window in tokens

Create the target directory with the correct ownership, then reload and restart:

Console
$ sudo mkdir -p /var/lib/ollama/models
$ sudo chown -R ollama:ollama /var/lib/ollama
$ sudo systemctl daemon-reload
$ sudo systemctl restart ollama

Exposing the API to other hosts

Setting OLLAMA_HOST=0.0.0.0:11434 makes the API reachable from the network. Ollama has no authentication of its own, so anyone who can reach the port can run inference, pull models and consume disk space. Restrict access at the firewall and terminate TLS plus authentication in front of it:

Console
$ sudo ufw allow from 10.0.0.0/24 to any port 11434 proto tcp

For anything reachable from the public internet, put a reverse proxy such as nginx or Caddy in front with HTTP basic auth or an API gateway, and leave Ollama itself bound to localhost.

Pull and run a model

Download a small model first to confirm the whole path works:

Console
$ ollama pull llama3.2:3b

Start an interactive session:

Console
$ ollama run llama3.2:3b
>>> Summarize what systemd drop-in files do in two sentences.

Leave the session with /bye. The model stays loaded for the duration of OLLAMA_KEEP_ALIVE, so the next request answers without a reload. List and remove models with:

Console
$ ollama list
$ ollama rm llama3.2:3b

Model files are large and grow quickly across a fleet of machines. Track the size of /var/lib/ollama/models in your monitoring alongside the usual disk metrics, and set a threshold well below full, because a failed pull on a full filesystem leaves partial blobs behind.

Verify the installation

Check the service state and the effective environment:

Console
$ systemctl is-active ollama
active
$ systemctl show ollama --property=Environment

Query the list of installed models over the API:

Console
$ curl -s http://127.0.0.1:11434/api/tags | jq '.models[].name'
"llama3.2:3b"

Send a single non-streaming completion:

Console
$ curl -s http://127.0.0.1:11434/api/generate -d '{"model":"llama3.2:3b","prompt":"Reply with the word OK.","stream":false}' | jq -r '.response'
OK

The OpenAI-compatible endpoint answers under /v1 and accepts any dummy API key:

Console
$ curl -s http://127.0.0.1:11434/v1/chat/completions -H "Content-Type: application/json" -d '{"model":"llama3.2:3b","messages":[{"role":"user","content":"ping"}]}' | jq -r '.choices[0].message.content'

If all four commands return output, the service is working and reachable.

Troubleshooting

Service restarts in a loop

Read the journal first:

Console
$ journalctl -u ollama -n 50 --no-pager

listen tcp 127.0.0.1:11434: bind: address already in use means a second instance is running, usually one started manually with ollama serve in a terminal. Find and stop it:

Console
$ sudo ss -lntp | grep 11434

Permission denied on the model directory

After changing OLLAMA_MODELS, the new path must belong to the ollama user. A log line containing permission denied on a path under /var/lib/ollama points to a missing chown. Re-apply ownership and restart the unit.

GPU is not used

The startup log states which backend was selected. Search for it:

Console
$ journalctl -u ollama | grep -i "inference compute"

If no GPU is listed, verify the driver with nvidia-smi. On a fresh Ubuntu 24.04 install, sudo ubuntu-drivers install pulls a matching NVIDIA driver. A reboot is required afterwards, and Ollama must be restarted so it re-detects the device.

Next steps

The installation is complete once systemctl is-active ollama reports active and /api/generate returns a response. Before putting the host to work, decide who may reach port 11434 and keep the API behind a firewall or an authenticating proxy. Then size the model to the hardware: a 3B model in 4-bit quantization fits comfortably in 8 GB RAM, while an 8B model at longer context lengths wants 16 GB or a GPU.

Read next

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

Ludwig Technische Redaktion

Schreibt bei centron über Linux-Administration, Container und Datenbanken – mit Fokus auf Anleitungen, die im Betrieb tatsächlich funktionieren.

Kategorie Ubuntu
Teilen
Noch offene Fragen?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

War dieses Tutorial hilfreich?

Your answer is stored anonymously and helps us improve our tutorials.

Kommentare

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren