How to Configure Automatic Update on Ubuntu server

This guide cover how to configure Ubuntu server to automatically install update packages, or just the security update packages.

First check if you have already installed “unattended-upgrades” package:

sudo apt-get install unattended-upgrades

Change /etc/apt/apt.conf.d/50unattended-upgrades if you what to install only security update or all:

Unattended-Upgrade::Allowed-Origins {
        "Ubuntu precise-security";
//      "Ubuntu precise-updates";

There are also options to install updates on shutdown or to automatically reboot if required. Change those options according your needs.

On /etc/apt/apt.conf.d/10periodic you can set when automatic update should run:

// How often the package list should update (1 means every day)
APT::Periodic::Update-Package-Lists "1";
// How often the upgradable packages should download
APT::Periodic::Download-Upgradeable-Packages "1";
// How often install the upgradable packages
APT::Periodic::Unattended-Upgrade "1";
// How often clean the download archive
APT::Periodic::AutocleanInterval "7";

The above configuration updates the package list, downloads, and installs available upgrades every day. The local download archive is cleaned every week.

For more option check the script: /etc/cron.daily/apt

The results of unattended-upgrades will be logged to /var/log/unattended-upgrades.

Anacron makes sure that all the tasks listed in /etc/cron.hourly , /etc/cron.daily , /etc/cron.weekly and /etc/cron.monthly are performed.

You can check /etc/crontab to check if the time of scheduled APT job is fine for you (the default for daily task is 6:25AM):

# m h dom mon dow user	command
17 *	* * *	root    cd / && run-parts --report /etc/cron.hourly
25 6	* * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6	* * 7	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6	1 * *	root	test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )

I do not set automatically reboot (if needed) on unattended-upgrades setting, so I scheduled a weekly reboot:
Create this script: sudo nano -w /etc/cron.weekly/zz-reboot (I call it zz-reboot because will be, like this the last task that anacron will run).

shutdown -r now

You can change “now” option with the minutes of delay you like before the shutdown.
For making the Cron Job file executable run this command:

sudo chmod 755 /etc/cron.weekly/zz-reboot



One thought on “How to Configure Automatic Update on Ubuntu server

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s