Running Ollama as a Systemd Service
What this article covers
- How to run Ollama with Systemd as a service.
- How to set environment variables and options.
- How to check status, restart, and troubleshoot.
- How to operate Ollama reliably in the background.
Introduction: Ollama as a Systemd Service
If you run Ollama regularly on a server or in a Proxmox LXC container, you don’t want to manually start the program after every reboot. Systemd is the standard service manager on most Linux distributions and works well for automatically starting Ollama, monitoring it, and restarting it if it crashes.
This article explains how to configure, customize, and maintain the Ollama Systemd service.
Key concepts
- Systemd: Init system and service manager for Linux.
- Service: Configuration for a persistent process.
- Unit file: File that describes the service.
- Environment: Environment variable for the service.
- Override: Supplementary configuration that extends the main config.
- Restart policy: Behavior when the service crashes.
- Journal: System log for services.
Standard installation
When you install Ollama with the official installation script, it typically creates a Systemd unit. Check with:
systemctl status ollama
If the service exists, it’s probably already enabled and running in the background.
Manual service file
If no unit exists, create one manually:
sudo tee /etc/systemd/system/ollama.service <<EOF
[Unit]
Description=Ollama Service
After=network.target
[Service]
Type=simple
User=ollama
Group=ollama
WorkingDirectory=/home/ollama
ExecStart=/usr/local/bin/ollama serve
Restart=on-failure
RestartSec=10
Environment="HOME=/home/ollama"
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
[Install]
WantedBy=multi-user.target
EOF
Then:
sudo systemctl daemon-reload
sudo systemctl enable --now ollama
Setting environment variables
Custom environment variables should not be edited directly in the main service file. Use an override file instead:
sudo systemctl edit ollama
A text editor opens. Example:
[Service]
Environment="OLLAMA_HOST=127.0.0.1:11434"
Environment="OLLAMA_NUM_PARALLEL=2"
Environment="OLLAMA_MAX_LOADED_MODELS=1"
Environment="CUDA_VISIBLE_DEVICES=0"
Then:
sudo systemctl daemon-reload
sudo systemctl restart ollama
Important environment variables
- OLLAMA_HOST: Bind address and port.
- OLLAMA_NUM_PARALLEL: Number of parallel requests.
- OLLAMA_MAX_LOADED_MODELS: Maximum number of models loaded simultaneously.
- OLLAMA_MODELS: Alternative path for model files.
- CUDA_VISIBLE_DEVICES: Select specific Nvidia GPU.
- HIP_VISIBLE_DEVICES: Select specific AMD GPU.
Checking status
systemctl status ollama
systemctl is-active ollama
systemctl is-enabled ollama
Viewing logs
journalctl -u ollama -f
journalctl -u ollama --since "1 hour ago"
Restart, stop, and start
sudo systemctl restart ollama
sudo systemctl stop ollama
sudo systemctl start ollama
Checking GPU usage
ollama ps
nvidia-smi
When Ollama runs under Systemd, the service user needs GPU access. The service user should be a member of the video or render group, for example.
Security
- Don’t run as root: A dedicated
ollamauser is more secure. - Restrict OLLAMA_HOST: Default is
127.0.0.1; only bind to the network if necessary. - No secrets in the unit file: Don’t store API keys or passwords directly.
- File permissions: The model directory should be owned by the
ollamauser.
Multiple Ollama instances
For separate models or users, you can define multiple services, such as ollama-8b.service and ollama-70b.service, listening on different ports. This is only useful in special cases, as multiple instances can duplicate memory usage.
Common pitfalls
- Service won’t start: Incorrect user or path.
- GPU not detected: User missing from
video/rendergroup, or driver not installed. - Port already in use: Another process is using
11434. - Model directory not found:
OLLAMA_MODELSset incorrectly or insufficient permissions. - Override not loaded: Forgot to run
systemctl daemon-reload. - Too many parallel requests: System is overloaded.
Further reading
- BotServ.de Ollama Performance
- BotServ.de Securing Ollama
- BotServ.de Proxmox LXC vs. VM
- BotServ.de Proxmox Storage
FAQ: Ollama as a Systemd Service
Does Ollama start automatically?
Yes, if the service was enabled with systemctl enable.
Where do I find the Ollama logs?
Use journalctl -u ollama.
How do I set environment variables?
Via systemctl edit ollama in an override file.
Can I run Ollama as root? Technically yes, but not recommended for security reasons.
What if Ollama doesn’t start at boot?
Check systemctl status ollama and journalctl -u ollama.
Sources and further reading
- Ollama Docs: https://github.com/ollama/ollama/blob/main/docs/
- Systemd ExecStart: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html
- journalctl: https://www.freedesktop.org/software/systemd/man/latest/journalctl.html


