通过 cron 设置定时任务,定期执行更新命令:
crontab -e
0 3 * * * apt update && apt upgrade -y
0 3 * * *
:时间格式(分 时 日 月 周),表示每天凌晨3点。apt update
:更新软件包列表。apt upgrade -y
:升级所有可升级的软件包(-y
自动确认)。sudo sed -i 's/当前版本号/目标版本号/g' /etc/apt/sources.list
sudo apt update
sudo apt full-upgrade
sudo reboot # 重启完成升级
安装工具并启用定时自动更新:
unattended-upgrades
:sudo apt install unattended-upgrades
sudo dpkg-reconfigure unattended-upgrades
sudo systemctl status apt-daily.timer apt-daily-upgrade.timer
sudo systemctl enable --now apt-daily.timer apt-daily-upgrade.timer
grep CRON /var/log/syslog