更新软件包列表:
sudo apt update
升级已安装的软件包:
sudo apt upgrade
完整系统升级(包括内核和依赖变更):
sudo apt full-upgrade
清理不再需要的包:
sudo apt autoremove
安装unattended-upgrades:
sudo apt install unattended-upgrades apt-listchanges
启用自动更新:
sudo dpkg-reconfigure -plow unattended-upgrades
选择"Yes"启用
配置自动更新设置:
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
修改以下内容:
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}";
"${distro_id}:${distro_codename}-security";
"${distro_id}:${distro_codename}-updates";
// 根据需要添加其他源
};
Unattended-Upgrade::AutoFixInterruptedDpkg "true";
Unattended-Upgrade::MinimalSteps "true";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
Unattended-Upgrade::Automatic-Reboot "false"; // 设置为true以允许自动重启
创建更新脚本:
sudo nano /etc/cron.weekly/apt-update
添加内容:
#!/bin/sh
apt-get update
apt-get upgrade -y
apt-get autoremove -y
赋予执行权限:
sudo chmod +x /etc/cron.weekly/apt-update
Automatic-Reboot
设为falseUnattended-Upgrade::Mail
接收更新通知sudo unattended-upgrade --dry-run
测试/var/log/unattended-upgrades/
sudo systemctl status unattended-upgrades
通过这些配置,你的Debian系统将能够自动保持更新,同时你可以根据需要调整自动更新的频率和范围。