Automatically update Arch Linux installed packages if there is a new update available is important to keep the packages up-to-date and it will provide improvement of security fixes, stability, performance, features, and more.
To keep the installed packages up-to-date, Arch Linux can automatically update if there is a new update available using a systemd service and timer (scheduler). It also helps to protect against zero-day attacks and vulnerabilities.
Information: The automatic update service below cannot automatically resolve package conflict during upgrade process, it will automatically skip or cancel the update process if conflict is detected. To resolve package conflict, run "pacman -Syu" (upgrade command) manually.
Create autoupdate serviceCreate a systemd service (autoupdate.service) using a text editor such as nano:
sudo nano /etc/systemd/system/autoupdate.service
Add following to the autoupdate.service:
[Unit] Description=Automatic Update After=network-online.target [Service] Type=simple ExecStart=/usr/bin/pacman -Syuq --noconfirm TimeoutStopSec=180 KillMode=process KillSignal=SIGINT [Install] WantedBy=multi-user.targetThe autoupdate.service (autoupdate timer's dependency unit) require the network is up. On service stop systemd will send interrupt signal (SIGINT) then wait the process to stop, after 180 seconds (timeout) systemd.kill will terminate using SIGTERM signal. While installing a package, pacman will not immediately end the process after receive the interrupt signal (SIGINT), instead pacman will continue upgrading the package until finish, then quit the process. It will avoid the package to be broken or corrupted.
Create autoupdate timerCreate a systemd timer or scheduler (autoupdate.timer) using a text editor such as nano to run the automatic updates periodically (e.g. every 45 minutes):
sudo nano /etc/systemd/system/autoupdate.timer
Add following to the autoupdate.timer:
[Unit] Description=Automatic Update when booted up after 5 minutes then check the system for updates every 60 minutes [Timer] OnBootSec=5min OnUnitActiveSec=60min Unit=autoupdate.service [Install] WantedBy=multi-user.target
Enable the autoupdate.timer to automatically run at startup:
sudo systemctl enable /etc/systemd/system/autoupdate.timer
Package was broken and corrupted after interrupted install/updateIf the automatic update were running when installing a package, but interrupted after power failure or system crash, then you receive an error when running pacman (e.g. error: target not found: package). Try to force re-install the broken or corrupted package then uninstall the package using following commands:
sudo pacman -S --force package && sudo pacman -R packageIf you're encountered a conflicting file issue on upgrading process in example "gd: /directory/file/ exists in filesystem" you can try to force pacman to upgrade the package:
sudo pacman -Syu --forceNote: Use the "--force" command to force package to be removed or upgraded, but use carefully. If the above steps doesn't work you can try another method from ArchWiki pacman's guide