Automatic updates for Raspberry Pi

Unattended upgrades for Raspberry Pi

This guide will help you to install automatic updates for Raspberry Pi

Unattended upgrades for Raspberry Pi is a must!

It is very important that you regularly update any OS of any kind of computer, whether it is a laptop or a built-in computer in your refrigerator. Hackers use previously found vulnerabilities in your OS. If you have closed it with the latest updates, then at least they can no longer use these vulnerabilities.

Standard update commands

The standard update commands, which you should run regularly, are:

sudo apt update
sudo apt upgrade

The first line retrieves the latest versions of the apps installed on your Raspberry. The second line will actually install them. You can choose to run these commands regularly. But you can also automate them:

Automate the updates

There is a program within Linux that allows you to schedule commands. You should see it as a kind of alarm clock, where you set the alarm to go off at certain times, but you can also have an action carried out immediately. That little program is called the crontab and you can set it with:

sudo crontab -e

When you first start this on your Raspberry, you will be asked which editor you want to edit the file with. It is a configuration file that you edit. I always choose nano, purely because that is what I work with the most.

A text document opens with an explanation of how to configure the crontab. It is quite complex, you do not need to know everything for this action, scroll to the last line and add the following lines:

0 1 * * *  sudo /usr/bin/apt update -y > /var/log/automaticupdates.log
15 1 * * *  sudo /usr/bin/apt upgrade -y >> /var/log/automaticupdates.log

Leave the crontab file (with <ctrl – x> and save the changes (y, and <enter>). If you enter correctly you will get the answer: crontab: installing new crontab.

You have now automated the update. Every day at 1:00 am a check will be made for new updates and they will be installed at 1:15 am. Furthermore, the resulting messages are stored in the log folder in the automaticupdates.log file.

Check operation of automatic updates

The next day (or if you have been running it for a while) you can check whether the file is working. To do this, type the following command:

cat /var/log/automaticupdates.log

You can see in the overview whether updates have been carried out, check whether there are also error lines in the log.

If you are looking for an post about installing a Raspberry Pi, hit Installing a Raspberry Pi

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *