Automatic Ollama Updates
Name: Kirill Reshetnikov Contacts: kiryxa20692@gmail.com About: System engineer, passionate about process automation, microservices, and optimizing high-load systems. Links:
Greetings!

Let’s look at how to set up automatic Ollama updates on Debian 13 while preserving custom systemd unit parameters.

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:

SoftwareVersion
Debian13.4
Ollama0.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:

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:

BASH
sudo systemctl edit ollama.service
Click to expand and view more

In 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:

INI
### 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 discarded
Click to expand and view more

Save the changes and verify that the override.conf file has been created in the /etc/systemd/system/ollama.service.d/ directory.

BASH
sudo cat /etc/systemd/system/ollama.service.d/override.conf
Click to expand and view more

The result should be a file with fixed parameters that will not be overwritten when updating.

BASH
╭─(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"
Click to expand and view more

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:

BASH
sudo vim /usr/local/bin/update-ollama.sh
Click to expand and view more

Add the following code to it:

BASH
#!/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
fi
Click to expand and view more

Script logic:

  1. Determine the current version of Ollama on the server and store the obtained value in the current variable;

  2. Check the current version from the GitHub repository and store it in the latest variable;

  3. Then compare the versions:

    • If current matches latest, script execution ends;
    • If a new version is found, the official installation script is run, which updates Ollama, after which the service is restarted.

Save the changes to the file and add execute permissions:

BASH
sudo chmod +x /usr/local/bin/update-ollama.sh
Click to expand and view more

Next, 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:

BASH
sudo crontab -e
Click to expand and view more

Add a line like this:

BASH
00 02 * * 4 /usr/local/bin/update-ollama.sh
Click to expand and view more

Save 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:

BASH
sudo vim /etc/systemd/system/ollama-update.service
Click to expand and view more

Add the following content to it:

INI
[Unit]
Description=Update Ollama

[Service]
Type=oneshot
ExecStart=/usr/local/bin/update-ollama.sh
Click to expand and view more

Then create the timer unit file:

BASH
sudo vim /etc/systemd/system/ollama-update.timer
Click to expand and view more

Add the following content:

INI
[Unit]
Description=Run Ollama Weekly Updates

[Timer]
OnCalendar=Thu 02:00
Persistent=true

[Install]
WantedBy=timers.target
Click to expand and view more

After that, reload the systemd configuration:

BASH
sudo systemctl daemon-reload
Click to expand and view more

And add the timer to autostart:

BASH
sudo systemctl enable ollama-update.timer
Click to expand and view more

Now 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.

Comments

Copyright Notice

Author: Kirill Reshetnikov

Link: https://r4ven.me/en/automation/avtomaticheskoe-obnovlenie-ollama/

License: CC BY-NC-SA 4.0

Blog materials may be used with attribution to the author and source, for non-commercial purposes, and under the same license.

Start searching

Enter keywords to search articles

↑↓
ESC
⌘K Shortcut