How do I set my system to auto-update without user interaction?
Solution 1:
Install the unattended-upgrades
package, and edit its config file to install all packages, not just security updates:
Edit the file /etc/apt/apt.conf.d/50unattended-upgrades
:
// Automatically upgrade packages from these (origin, archive) pairs
Unattended-Upgrade::Allowed-Origins {
"${distro_id} ${distro_codename}-security";
// "${distro_id} ${distro_codename}-updates";
// "${distro_id} ${distro_codename}-proposed";
// "${distro_id} ${distro_codename}-backports";
};
and remove the //
from the parts you want to be automatic and then just save the file.
Next you need to set the autoupdate functions in /etc/apt/apt.conf.d/10periodic
:
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";
The update interval is every day, which is about right, otherwise you'd probably be hitting the mirror too often.
Here's the documentation for this:
- https://help.ubuntu.com/10.04/serverguide/C/automatic-updates.html
Solution 2:
Automatic Daily Package Updates Using Cron And Apt-Get
WARNING: As with any system changes, the potential for creating new or additional problems may occur. Please be sure to backup your data and configurations! Use this document at your own risk.
Creating the Daily Cron Job File
First you will need to create the cron job file. You can use a simple text editor to create the file and save it in your home directory. In the Text Editor, type the following lines:
#!/bin/bash
apt-get update
apt-get upgrade -y
apt-get autoclean
Now click Save and name the file something like "autoupdt".
Moving the Cron Job File to Cron.Daily
Now that you have created the cron job file, it needs to be moved into the daily cron directory so that it will be run automatically on a daily basis. To do this, we first need to open a command line terminal (CTRL+ALT+T).
We need to move the file to the proper directory. Type the following command at the command line prompt to move the file:
sudo mv /where/ever/autoupdt /etc/cron.daily
Making the Cron Job File Executable
Now that the file is created and ready to be run daily by cron, we still need to make the file executable in order for cron to be able to run it.
sudo chmod 755 /etc/cron.daily/autoupdt
Follow-up
For more details on custom configuration of cron, please refer to:
man cron
Finished