Ollama as user systemd service
Sometimes I need a service to run when my user is logged in, otherwise the service can run
like the other services when the machine start, systemd can provide that functionality.
Ollama
Ollama is one of the tools that allows you to run large language models locally. There are other tools like Unsloth Studio, llama.cpp, LM Studio, but Ollama is the simplest.
curl -fsSL https://ollama.com/install.sh | shBy default, running the installation script will attempt to create a user ollama and systemd unit file to run the service when the machine starts.
Also, there is the manual installation method if you don’t want to blindly run scripts from the internet
curl -fsSL https://ollama.com/download/ollama-linux-amd64.tar.zst | sudo tar x -C /usrThen you can run Ollama directly with your user using
ollama serveSetup as local service for user
If the installation script was used, we disabled like this:
sudo systemctl disable --now ollamaThen we create a systemd unit file for the user
mkdir -p ~/.config/systemd/user/
touch ~/.config/systemd/user/ollama.serviceThe content of the systemd unit file
[Unit]
Description=Ollama Service
After=network-online.target
[Service]
ExecStart=/usr/local/bin/ollama serve
Restart=always
RestartSec=3
# custom options
Environment="OLLAMA_HOST=127.0.0.1" # 0.0.0.0 or IP address if we want to expose the service
Environment="OLLAMA_CONTEXT_LENGTH=131072" # context windows size 128k
Environment="OLLAMA_NO_CLOUD=1" # if we don't require cloud models, set 0 or remove if subscription is available
Environment="OLLAMA_GPU=100" # make ollama use the GPU full before doing the offloading in the CPU/Memory
Environment="OLLAMA_KV_CACHE_TYPE=q4_0" # set the quantization type for the K/V cache
[Install]
WantedBy=default.targetAfter the file was created we only need to tell systemd about it
# make the system detect the new unit
systemctl --user daemon-reload
# verify the service
systemctl --user status ollama
# enable
systemctl --user enable --now ollama
# check status
systemctl --user status ollama
● ollama.service - Ollama Service
Loaded: loaded (/home/jms/.config/systemd/user/ollama.service; enabled; preset: disabled)
Drop-In: /usr/lib/systemd/user/service.d
└─10-timeout-abort.conf
Active: active (running) since Thu 2026-07-02 11:33:50 CST; 15s ago
Invocation: 31d160b7ba1b4e0482156a3005bc26b0
Main PID: 91111 (ollama)
Tasks: 16 (limit: 154263)
Memory: 16.2M (peak: 285M)
CPU: 2.719s
CGroup: /user.slice/user-1000.slice/[email protected]/app.slice/ollama.service
└─91111 /usr/local/bin/ollama serve