Automatic Updates : Ubuntu (all versions)

By | 2006/10/07

Below is a quick hack to have your Ubuntu machine automagically update for you at a pre-specified time. This includes the “update”, “upgrade”, “dist-upgrade” and “autoclean” commands. The scheduling is taken care of by cron, our trusty always-on-time friend.

sudo crontab -e

It is important that you use sudo at this point. The command will need super-user priveleges so the cron listing needs to be setup as the root user.

0 0 * * * aptitude -y update && aptitude -y upgrade && aptitude -y dist-upgrade && aptitude -y autoclean

The above line represents the listing put into the crontab file. Here is a quick explanation of the five fields you can specify for the date and time. (The above executes daily at midnight)

minute - hour - day of month - month - day of week

After you have specified the appropriate time and date for your system simply save the file and your system will now automagically upgrade at the time specified. These upgrades include regular updates, kernel updates, security updates, etc. Also, the “autoclean” command removes old packages from your system after they are no longer needed.

Of course, if you prefer not to have cron take care of everything (if you’d still like to be somewhat hands-on) you could simply run the command in a single line:

sudo aptitude -y update && sudo aptitude -y upgrade && sudo aptitude -y dist-upgrade && sudo aptitude autoclean

technorati tags:, , , , , , , ,

15 thoughts on “Automatic Updates : Ubuntu (all versions)

  1. Pingback: Planeta Debian » Christer Edwards: Package Management with APT : Ubuntu (all versions)

  2. datakid

    This may sound stupid, but I did this and it failed.

    I realised at the time it might fail, but I took a punt.

    The weak point is here: you do not say where to save the newly created crontab file. So mine ended up in tmp I think. It’s probably still there, and I still have a bunch of updates to do.

    Where should it be saved?

  3. Boter

    That’s very dangerous if you have custom .conf files. eg for ssh, ftp-d clients and so on… because -y overwrites old config files.

  4. Pingback: Steve Miller’s Web Sites of Interest » links for 2007-05-16

  5. Alberto

    In regards to overwritten conf files, just back them up so you can restore them if necesary.

  6. gioby

    Wouldn’t it be better to use anacron instead of cron?

    What if the machine is off power when the cron job is programmed to be run?

  7. Eric

    fix this posting. this is as clear as mud!!!

  8. trlkly

    RE:anacron

    By default on Ubuntu systems, anacron is set up to automatically run cron jobs that don’t get executed on time.

    At least, that’s what I think the settings in /etc/anacrontab mean. Check them yourself.

  9. trlkly

    Post this only if I’m right:

    If you are running GUI, you might want to disable the Automatic Updates under System -> Administration -> Software Sources -> Updates, so you aren’t doing the same job twice.

  10. Levi

    To compensate aptitude overwriting config files sometimes I made a script that backs up all my custom configuration files, runs the aptitude command, then copies the config files back. I then set that script to run as a cron job. It's pretty simple, and ensures I don't lose any configuration files while allowing me to make changes to confs without then explicitly backing them up.

  11. Suits

    Isn't there something built into apt-get or aptitude to run as a service?

  12. Suits

    Isn't there something built into apt-get or aptitude to run as a service?

Comments are closed.