Let’s look at how to set up automatic Ollama updates on Debian 13 while preserving custom systemd unit parameters.
🖐️Hey!
Subscribe to our Telegram channel @r4ven_me📱, so you don’t miss new posts on the website 😉. If you have questions or just want to chat about the topic, feel free to join the Raven chat at @r4ven_me_chat🧐.
Introduction
When installing Ollama to a server, the version that is current at the moment of script execution is installed. This installation method is official, but does not provide automatic updates, so this task needs to be implemented separately.
Software used in the article:
| Software | Version |
|---|---|
| Debian | 13.4 |
| Ollama | 0.32.0 |
Fixing changes in the unit file
When installing ollama on a physical server or virtual machine, you will most likely need to make changes to the ollama.service unit file.
In a standard usage scenario, the following parameters are typically set:
- custom path to the models repository;
- permission to listen on an interface other than
localhost; - limits on the number of models simultaneously loaded into memory;
- a timer after which a model will be automatically unloaded if there are no active requests to it.
If you edit the existing unit file directly, the changes will be overwritten when Ollama is updated. Therefore, customizations should be fixed through the override mechanism in systemd.
Open the unit file for editing using the command:
📝 Note
Note that executing commands will require sudo privileges.
sudo systemctl edit ollama.serviceIn the area between the second and fifth lines, add the [Service] section and specify the necessary parameters similar to the main ollama.service unit file.
In our example, it looks like this:
### Editing /etc/systemd/system/ollama.service.d/override.conf
### Anything between here and the comment below will become the contents of the drop-in file
[Service]
Environment="OLLAMA_MODELS=/opt/ollama/models"
Environment="OLLAMA_HOST=0.0.0.0:11434"
Environment="OLLAMA_MAX_LOADED_MODELS=1"
Environment="OLLAMA_KEEP_ALIVE=5m0s"
### Edits below this comment will be discardedSave the changes and verify that the override.conf file has been created in the /etc/systemd/system/ollama.service.d/ directory.
sudo cat /etc/systemd/system/ollama.service.d/override.confThe result should be a file with fixed parameters that will not be overwritten when updating.
╭─(00:06:32)-(0)-(llm-b01-p)-[~]
╰─[ansible]$ sudo cat /etc/systemd/system/ollama.service.d/override.conf
[Service]
Environment="OLLAMA_MODELS=/opt/ollama/models"
Environment="OLLAMA_HOST=0.0.0.0:11434"
Environment="OLLAMA_MAX_LOADED_MODELS=1"
Environment="OLLAMA_KEEP_ALIVE=5m0s"After fixing the unit file configuration, you can proceed to automating updates.
Setting up automatic updates
The simplest way to automate Ollama updates is to use a script with version checking.
Create an executable file, for example /usr/local/bin/update-ollama.sh using a text editor vim:
sudo vim /usr/local/bin/update-ollama.shAdd the following code to it:
#!/usr/bin/env bash
set -euo pipefail
current=$(ollama -v | grep 'version' | awk '{print $NF}')
latest=$(curl -s https://api.github.com/repos/ollama/ollama/releases/latest \
| grep tag_name | cut -d '"' -f4 | sed 's/^v//')
if [ "$current" != "$latest" ]; then
curl -fsSL https://ollama.com/install.sh | sh
systemctl restart ollama
fiScript logic:
Determine the current version of Ollama on the server and store the obtained value in the
currentvariable;Check the current version from the GitHub repository and store it in the
latestvariable;Then compare the versions:
- If
currentmatcheslatest, script execution ends; - If a new version is found, the official installation script is run, which updates Ollama, after which the service is restarted.
- If
Save the changes to the file and add execute permissions:
sudo chmod +x /usr/local/bin/update-ollama.shNext, you need to configure the schedule for its execution, for example, once a week on Thursday at 02:00.
Option 1: cron
The simplest way - add an entry to the cron scheduler of the root user:
sudo crontab -eAdd a line like this:
00 02 * * 4 /usr/local/bin/update-ollama.shSave the changes and exit the text editor.
Option 2: systemd timer
An alternative option is to use the systemd timer.
First, create the service unit file:
sudo vim /etc/systemd/system/ollama-update.serviceAdd the following content to it:
[Unit]
Description=Update Ollama
[Service]
Type=oneshot
ExecStart=/usr/local/bin/update-ollama.shThen create the timer unit file:
sudo vim /etc/systemd/system/ollama-update.timerAdd the following content:
[Unit]
Description=Run Ollama Weekly Updates
[Timer]
OnCalendar=Thu 02:00
Persistent=true
[Install]
WantedBy=timers.targetAfter that, reload the systemd configuration:
sudo systemctl daemon-reloadAnd add the timer to autostart:
sudo systemctl enable ollama-update.timerNow Ollama will be updated automatically every Thursday at 02:00 regardless of which startup option you choose.
Conclusion
In this article, we reviewed the process of organizing automatic Ollama updates on a Debian 13.4 server. We fixed user changes in the unit file through the systemd override mechanism, which allows you to preserve your configuration during updates. To prevent unnecessary update process runs, the script uses version checking and rebuilds Ollama only when a new release is available.
Special attention was paid to choosing an automation approach - using cron or systemd timer. Both options provide a predictable and controlled update process without the need for manual intervention. This approach allows you to maintain your Ollama server in an up-to-date state, minimizing downtime risk and ensuring you get the latest fixes and improvements.
👨💻And…
Don’t forget about our Telegram channel 📱 and chat
Or maybe you want to become a co-author? Then click here🔗
💬 All the best ✌️
That should be it. If not, check the logs 🙂



Comments