How To Automatically Update Ubuntu


How to automatically update Ubuntu

Today, Ubuntu Linux is a popular choice for servers and even for some desktops. Linux, as a whole, is known for its stability and suitability which makes it excellent operating system for web and email servers. But no operating system stays secure forever because new security holes are found on a frequent basis. The obvious solution is to update your Ubuntu, but how?

The problem

The problem is actually very simple. You can update Ubuntu with a simple command from the shell, but do you actually remember to do it often? Previously, I can not count how many times I just forgot to update my Ubuntu installation for weeks, even months. This creates a security hole a skilled hacker can exploit. And even if you absolutely remember to upgrade your Ubuntu every few days, you still have to log in and write the command. It can become a nuisance in the long term but since we are talking about computers, everything can be automated!

Solution #1

Use unattended-upgrades package. Install and configure it with the following commands in the shell:

sudo apt-get install unattended-upgrades
sudo dpkg-reconfigure unattended-upgrades

Answer the questions the dpkg-reconfigure asks you. Now you will have updates running as they occur, silently on the background. Just what we wanted, right?

Solution #2

Put the following command running to the root’s cron of your Ubuntu system:

0 21 * * * root /usr/bin/apt-get update && /usr/bin/apt-get upgrade -q -y >> /var/log/apt/autoupdate.log

This will run apt-get update and apt-get upgrade every day at 9PM. The upgrade command will have -q and -y flags which mean quiet (produce less output) and assuming yes to prompts. It will also put the logging data to the specified directory. In essence, the command will automatically update your Ubuntu every day!

Any problems with these methods?

Having automatic updates could potentially mean that something on your server stops working. On the other hand, not having automatic updates (and forgetting to update manually) means you make the server vulnerable to malicious hackers. So you have to weigh in the risks, but I’d say for most people having some sort of automatic update is the way to go. Or what do you think?

About the author

Akseli Niemelä is an Internet entrepreneur with keen interest for technology, programming and human relations. He has been writing a blog since 2010, with current orientation for content-rich websites. For more information, please read the About section of this website.

Share Your Thoughts

Have something to say about this post? Then say it by filling the form below!