# Upgrade Debian 8 Jessie to Debian 9 Stretch

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Jan 12, 2019, updated Nov 18, 2019. Topics: Debian, DevOps.
Canonical URL: https://attacomsian.com/blog/upgrade-debian-8-Jessie-to-debian-9-stretch

> 

Debian 9 Stretch comes with a significant amount of new and updated packages as well as a score of packages had been marked obsolete. <!--more--> According to [Debian release notes](https://www.debian.org/releases/stretch/mips/release-notes/ch-whats-new.en.html), the new release has a lot more software than its predecessor Jessie. The distribution includes a total of over 51687 packages, of which over 15346 are new packages. The majority of the software in Stretch has been updated: over 29859 software packages that are around 57% of all packages in Jessie. There are 6739 packages which are removed from Stretch due to various reasons.

In this tutorial, I will explain the process to upgrade Debian 8 Jessie to Debian 9 Stretch in a few simple steps. 

## Backup the data and configuration files

Before you start with the actual upgrade, first make sure that you back up all critical data and configurations. This especially includes configuration data in `/etc` directory and the user data in `/home`. If you are running a database server like MySQL or PostgreSQL on Debian 8, consider creating a backup of all your databases. The easiest way to backup everything is to create a server snapshot. For AWS EC2 or Digital Ocean droplet, you can create a snapshot from your server settings. If anything goes wrong during the upgrade, you will be able to revert back to the old setup by restoring a snapshot. 

## Update Debian 8 packages

Before upgrading to Stretch, we will first install all available Jessie updates. To avoid an unwanted early upgrade to Stretch, you should first check the `sources.list` file to ensure that it only contains `jessie` sources and no `stable` sources. Run the following command to open the `sources.list` file on a command-line editor:

```bash
$ nano /etc/apt/sources.list
```

Make sure your `sources.list` contains the following:

```bash
deb http://httpredir.debian.org/debian jessie main contrib non-free
deb http://httpredir.debian.org/debian jessie-updates main contrib non-free
deb http://security.debian.org jessie/updates main contrib non-free
```

Now run the following commands to install and upgrade all the pending and current Jessie packages. It will make sure that your system is update-to-date for the upgrade to Stretch.

```bash
$ apt update
$ apt upgrade
$ apt dist-upgrade
```

Before we proceed with the Stretch upgrade, check the package state to ensure that there are no packages on hold or in the half-installed state with the following commands:

```bash
$ dpkg --audit
$ dpkg --get-selections | grep hold
```
If both commands return nothing, then proceed with the next step.

## Upgrade to Debian 9 Stretch

First of all, edit `sources.list` file again and replaces its content with the following lines:

```bash
$ nano /etc/apt/sources.list
```

```bash
deb http://httpredir.debian.org/debian stretch main contrib non-free
deb http://httpredir.debian.org/debian stretch-updates main contrib non-free
deb http://security.debian.org stretch/updates main contrib non-free
```

Save the file and then run the following commands to update and upgrade packages to Stretch:

```bash
$ apt update
$ apt upgrade
$ apt dist-upgrade
```

The last command will do the distribution upgrade to Debian 9 Stretch. If everything goes well, your server will be upgraded to Debian 9 Stretch. A reboot is required to finish the upgrade and to load the new kernel. Run the following command in your terminal to reboot:

```bash
$ reboot
```

That's all. If you want to check which Debian version you are currently running, execute the following command to take a look at the file `/etc/os-release`.

```bash
$ cat /etc/os-release
```
