Raspberry Pi

Updating the Raspberry Pi

As with any other Linux system, the update / upgrade path for the Raspberry Pi is rather straightforward. This recipe summarizes the approach for your device and the extras available specifically for Raspberry Pi. However, equipped with this knowledge, you are becoming a Linux updat pro as well :)

Note: Recently, the Debian ecosystem has received a significant boost in the update mechanisms. You might want to check an easier way of upgrading your system using apt. Below, we show both approaches (marking the older alternatives as 'old style'). In a nutshell - apt is new and recommended, apt-get works, but is 'old style'. Apart from some simplifications, apt also brings you a better 'graphical experience'

update

First thing to run on your device is an update

sudo apt update

Old Style:

sudo apt-get update

This downloads the package lists from available repositories and updates your system with the latest information on newest versions of packages and their dependancies. It will do this for all available repositories. An update should always be performed before an upgrade or dist-upgrade.

apt update does not actually install any new version of software

upgrade

After update we are actually ready to install the latest versions of all packages currently installed on the system. Note that sources are listed in /etc/apt/sources.list. It does not remove any old packages. To invoke, run

sudo apt upgrade

Old Style:

sudo apt-get upgrade

Packages currently installed with new versions available are retrieved and upgraded; under no circumstances are currently installed packages removed, nor are packages that are not already installed retrieved and installed.

New versions of currently installed packages that cannot be upgraded without changing the install status of another package will be left at their current version.

full-upgrade

This is a new member of the update commands. Comes only with apt, and replaces all the hard work of using dist-upgrade (below) and autoremove.

This is a typical usage of your update cycle. In fact, you don't need anything else for updating the system. You might still want to check Rasperry Pi specific updates below though.

sudo apt update && sudo apt full-upgrade

dist-upgrade

The dist-upgrade will do the same job as upgrade, but on top will intelligently handle dependencies. This means it can remove obsolete packages or add new ones. To run, type the following

In the apt world, the partial equivalent of this is full-upgrade, see above.

Old Style:

sudo apt-get dist-upgrade

In addition to performing the described upgrade, this option also intelligently handles changing dependencies in new package versions. If needed, it will try to upgrade the most important packages at the expense of less important ones.

rpi-update

This is a special feature for Raspberry Pi. It allows updating the firware in an easy and fully automated way. Obviously please make sure your system is well updated before running the rpi-update.

To invoke, type the following (notice this is not a feature of apt-get, you are running a separate utility):

sudo rpi-update

In some Raspberry Pi distributions the rpi-update is bundled, in some not. If not found, you can easily download:

sudo apt-get install rpi-update

If the rpi-update did find and upgrade you to a new version of the firmware, a reboot is required.

To check the current firmware version without running rpi-update, just type

uname -a

autoremove

Over time and several updates, applications and packages installed will also install and share many libraries. Removing any application, the dependencies will stay on the system. This is where autoremove comes in. It will remove any and all dependencies no longer in use by anything on the system. To run, type

sudo apt-get autoremove

Summary

So to completely upgrade everything (assuming rpi-update is already installed), just type the following:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo rpi-update

You would of course run rpi-update once in a while, it is optional.

To chain all, just type the following - again with rpi-update being optional:

sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade && sudo rpi-update

Note on Chaining Commands:

Please note: the chaining command above executes each command in a row, waiting for the success of the previous command.

Here are other options for the command line:

A; B    Run A and then B, regardless of success of A
A && B  Run B if A succeeded
A || B  Run B if A failed
A &     Run A in background

Tips

Things rarely, if ever, go bad with the robust update mechanism the Pi has. Yet we can sometimes tackle things going wrong. Here are our tips to help you out.

repository is not valid yet

You might encounter the error repository is not valid yet - Updates for this repository will not be applied. We've seen this sometimes, when we restored a pre-configured image for other purposes.

The solution is fully described here, however the solution boils down to doing a time synchronization (or waiting longer).

Simply run the following:

timedatectl