How to Update Raspbian Jessie to Stretch


I have a project once which basically an SMS-based application using world's most popular IoT device: Raspberry Pi. I'd like to share some of my findings, so I guess this post will be part one.

The Story

One of project requirements need the latest version of Gammu, which not available on Jessie but available on Stretch. Another reason is PHP 7 is not available on Jessie. So, updating Raspbian on my Raspberry Pi from Jessie to Stretch is the way to go.

For the most part upgrading is a fairly simple process but be prepared to deal with some broken packages. Also make sure that any packages you are using now haven’t changed radically in some of the newer versions of Raspbian.

Update packages on Raspbian

Luckily for us updating packages on Raspbian is incredibly easy, it involves typing two very simple commands into terminal. It is good to remember the two commands that are shown below as they will quickly become some of your most used Linux commands.

$ sudo apt-get update
$ sudo apt-get upgrade

The first of these commands (sudo apt-get update) makes a call to the Advanced Packaging Tool (apt) to update the package list, this is highly important as the install and upgrade commands only search the pre-grabbed package list and don't make any attempts to update it themselves.

The update command works this by searching the /etc/apt/sources.list file, and then polling all the websites in the list for all available packages creating a list of their download location and their current version.

The default location that Raspbian uses for its packages can be found on Raspbians mirror director, this mirror director is designed to automatically direct you to the closest download provider.

Failing to run the update command before running install or upgrade could also cause you to run into download errors especially when packages are moved around on the mirror server.

The second command (sudo apt-get upgrade) again utilizes the Advanced Packaging Tool (apt), but this time it uses it to check all currently installed packages against the package list, if there is a version miss-match for any it will attempt to update it by downloading the new version from the link in the list. The upgrade tool will never remove a package.

Sometimes packages will be held back during an upgrade due to a change in the packages dependencies. To update the packages that are held back we must use a different command. That command is shown below:

$ sudo apt-get dist-upgrade

How to update Raspbian Jessie to Stretch

In this part of the article we will be exploring on how to update your Raspberry Pi from Raspbian Jessie to Raspbian Stretch.

Before we start the whole upgrade process make sure you backup your SD Card just in case this fails for some reason. You should also do this using a keyboard and mouse with direct access to your Raspberry Pi and not over SSH.

Before we begin switching our sources over to Stretch, we will first perform a full system upgrade to ensure we are running the latest available packages in Jessie. To do this run the following two commands in terminal:

$ sudo apt-get update
$ sudo apt-get upgrade -y

In some cases, packages may be held back, this is the last thing we want when upgrading the system to Stretch as it may cause some serious issues down the track. Let’s enforce upgrading to the held back packages by running the following command in terminal on the Raspberry Pi.

$ sudo apt-get dist-upgrade -y

In some cases, packages may be held back, this is the last thing we want when upgrading the system to Stretch as it may cause some serious issues down the track. Let’s enforce upgrading:

$ sudo rpi-update

Now to get Raspbian to update to stretch we need to modify the /etc/apt/sources.list file so it points to Raspbian Stretch instead of Jessie. Begin editing this file by running the following command in terminal:

$ sudo vi /etc/apt/sources.list

Now that we have done the initial updates we can now modify the sources.list file and comment out all occurrences of Jessie with Stretch, like we have shown below. We also add new line so that Raspbian will search the new Stretch repository for packages.


deb jessie main ui

Put a comment on that line and add new line above so that the file become like this:

deb stretch main contrib non-free rpi
# deb jessie main contrib non-free rpi

Save the file.

With that done we now need to modify the /etc/apt/sources.list.d/raspi.list file, this file adds additional sources to our sources.list file that we made modification to in the previous step. Run the following command to begin editing the file:

$ sudo vi /etc/apt/sources.list.d/raspi.list

Now that we are editing the raspi.list file we need to change the first entry by replacing Jessie with Stretch.


deb stretch main ui

Just like sources.list file, put a comment on that line and add new line:

deb stretch main ui
# deb jessie main ui

Save the file.

To ensure we have a fast and smooth updating process, we will also need to remove the package called apt-listchanges. The reason for removing this package is to stop it from trying to load the changelog for the huge amount of packages that are going to be upgraded.

To remove this package, we need to run the following command in terminal on the Raspberry Pi.

$ sudo apt-get remove apt-listchanges

Now that we have finished updating both the raspi.list file and the sources.list file we can proceed with updating Raspbian to Stretch. Run the following two commands on your Raspberry Pi to begin the update process. Please be prepared for this to take several minutes or even hours as it is a rather extensive process.

$ sudo apt-get update
$ sudo apt-get dist-upgrade -y

You will have to pay attention during this installation process as time to time you will be required to input 'Y' and press Enter for the upgrade process to continue onwards.

With our Raspberry Pi now successfully updated to Raspbian Stretch there are a few more things we will want to do. During installation, many packages will be marked as no longer needed due to changed dependencies.

To remove these, we can simply type in the following command into the terminal on the Raspberry Pi:

$ sudo apt-get autoremove -y

After running autoremove we should also clean out the package cache, the command we will be using autoclean, will automatically remove any packages files that are no longer able to be downloaded, and are largely useless.

Run the following command in your Raspberry Pi’s terminal to automatically clean these packages up.

$ sudo apt-get autoclean

Finally the last thing we should do is reboot the Raspberry Pi to ensure it loads in all the new packages and services correctly. Simply run the following command in terminal to restart your Raspberry Pi.

$ sudo reboot

Final Words

I hope that you now know how to update Raspbian and that you now have a Raspberry Pi that has been successfully updated from Raspbian Jessie to Stretch. You can now continue on with working on some Raspberry Pi projects or just using your Pi as you would normally. If you run into any issues or have any feedback feel free to drop a comment below.



0 comment

Leave a reply

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