Updating Flatpaks automatically with systemd
Quick How-To Guide on settings up automatic Flatpak updates on a Linux system via systemd.
Software updates are a fundamental part of maintaining a secure and functional Linux system. Different distributions and package formats handle updates in various ways, some automatically, some manually, and some somewhere in between.
Snaps, developed by Canonical, are designed to update automatically in the background. This ensures that applications are always running the latest version without requiring user intervention.
Flatpaks, on the other hand, typically require manual updates unless explicitly configured otherwise. This gives users more control over when and how updates are applied, which can be beneficial for stability and predictability.
However, for those who prefer a hands-off approach, similar to how Snaps behave, Flatpaks can also be set up to update automatically using systemd, which is what the following guide focuses on.
Setting Up Auto-Updates for Flatpaks
Flatpaks installed system-wide (in /var/lib/flatpak) require manual updates by default. To automate this process, similar to how Snaps update, we can use systemd to run flatpak update periodically.
Creating systemd Service Files
Systemd service files define what command should be executed when the service is triggered. In our case, we want systemd to simply run flatpak update to update our flatpaks.
[Unit]
Description=Automatically update system Flatpaks
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/flatpak --system update -y
[Install]
WantedBy=multi-user.target/etc/systemd/system/auto-update-system-flatpaks.service
After=network-online.targetEnsures the service runs only after the network is available.Wants=network-online.targetEnsures the service depends on network connectivity and won't start before.ExecStart=/usr/bin/flatpak --system update -yUpdates all system-wide Flatpaks without prompting.WantedBy=multi-user.targetEnsures the service is enabled when the system boots into multi-user mode already (non-graphical).
Creating systemd Timer Files
While service files define what to run, timer files define when to run it. We’ll set up timers to execute the Flatpak updates automatically.
[Unit]
Description=Daily automatic update of system Flatpaks
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target/etc/systemd/system/auto-update-system-flatpaks.timer
OnCalendar=dailySpecifies that the service should run once per day.Persistent=trueDefines that if the system was off when the timer was supposed to trigger, it will run at the very next opportunity.WantedBy=timers.targetEnsures the timer is activated when the user logs in.
Enabling and Starting the Timers
Now that the service and timer files are in place, we need to enable and start them.
We run the following command as root to enable automatic system flatpak updates.
sudo systemctl enable auto-update-system-flatpaks.timerOnce we got it enabled, we can give the service an initial run.
sudo systemctl start auto-update-system-flatpaks.serviceOnce it finished running, we can check the logs of auto-update-system-flatpaks.service to verify everything was working as expected.
journalctl -u auto-update-system-flatpaks.serviceFinal Thoughts
The established systemd automation keeps flatpaks updated without manual checks. It runs updates when online, with flexible scheduling and missed-update recovery, hence reduces system maintenance.
Some might prefer it this way, some might want to point out that system/app updates should be done only on human oversight. I'd say it depends on personal preferences and the system criticality.