如何通过命令行升级 Debian 9 为 Debian 10
Debian
我们已经在先前的文章中看到如何安装 [Debian 10（Buster）](/article-11083-1.html)。今天，我们将学习如何从 Debian 9 升级为 Debian 10，虽然我们已将看到 Debian 10 和它的特色，所以这里我们不会深入介绍。但是可能读者没有机会读到那篇文章，让我们快速了解一下 Debian 10 和它的新功能。


![](/data/attachment/album/201908/01/085439kp8jtzp9f1phuuah.jpg)


在差不多两年的开发后，Debian 团队最终发布一个稳定版本，Debian 10 的代码名称是 Buster。Buster 是一个 LTS (长期支持支持)版本，因此未来将由 Debian 支持 5 年。


### Debian 10（Buster）新的特色


Debian 10（Buster）回报给大多数 Debian 爱好者大量的新特色。一些特色包括：


* GNOME 桌面 3.30
* 默认启用 AppArmor
* 支持 Linux 内核 4.19.0-4
* 支持 OpenJDk 11.0
* 从 Nodejs 4 ~ 8 升级到 Nodejs 10.15.2
* Iptables 替换为 NFTables


等等。


### 从 Debian 9 到 Debian 10 的逐步升级指南


在我们开始升级 Debian 10 前，让我们看看升级需要的必备条件：


#### 步骤 1) Debian 升级必备条件


* 一个良好的网络连接
* root 用户权限
* 数据备份


备份你所有的应用程序代码库、数据文件、用户账号详细信息、配置文件是极其重要的，以便在升级出错时，你可以总是可以还原到先前的版本。


#### 步骤 2) 升级 Debian 9 现有的软件包


接下来的步骤是升级你所有现有的软件包，因为一些软件包被标志为保留不能升级，从 Debian 9 升级为 Debian 10 有失败或引发一些问题的可能性。所以，我们不冒任何风险，更好地升级软件包。使用下面的代码来升级软件包：



```
root@linuxtechi:~$ sudo apt update && sudo apt upgrade -y
```

#### 步骤 3) 修改软件包存储库文件 /etc/sources.list


接下来的步骤是修改软件包存储库文件 `/etc/sources.list`，你需要用文本 `Buster` 替换 `Stretch`。


但是，在你更改任何东西前，确保如下创建一个 `sources.list` 文件的备份：



```
root@linuxtechi:~$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
```

现在使用下面的 `sed` 命令来在软件包存储库文件中使用 `buster` 替换 `stretch`，示例如下显示：



```
root@linuxtechi:~$ sudo sed -i 's/stretch/buster/g' /etc/apt/sources.list
root@linuxtechi:~$ sudo sed -i 's/stretch/buster/g' /etc/apt/sources.list.d/*.list
```

更新后，你需要如下更新软件包存储库索引：



```
root@linuxtechi:~$ sudo apt update
```

在开始升级你现有的 Debian 操作系统前，让我们使用下面的命令验证当前版本，



```
root@linuxtechi:~$ cat /etc/*-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@linuxtechi:~$
```

#### 步骤 4) 从 Debian 9 升级到 Debian 10


你做完所有的更改后，是时候从 Debian 9 升级到 Debian 10 了。但是在这之前，再次如下确保更新你的软件包：



```
root@linuxtechi:~$ sudo apt update && sudo apt upgrade -y
```

在软件包升级期间，你将被提示启动服务，所以选择你较喜欢的选项。


一旦你系统的所有软件包升级完成，就升级你的发行版的软件包。使用下面的代码来升级发行版：



```
root@linuxtechi:~$ sudo apt dist-upgrade -y
```

升级过程可能花费一些时间，取决于你的网络速度。记住在升级过程中，你将被询问一些问题，在软件包升级后是否需要重启服务、你是否需要保留现存的配置文件等。如果你不想进行一些自定义更改，简单地键入 “Y” ，来让升级过程继续。


#### 步骤 5) 验证升级


一旦升级过程完成，重启你的机器，并使用下面的方法检测版本：



```
root@linuxtechi:~$ lsb_release -a
```

如果你获得如下输出：



```
Distributor ID: Debian
Description:    Debian GNU/Linux 10 (buster)
Release:        10
Codename:       buster
root@linuxtechi:~$
```

是的，你已经成功地从 Debian 9 升级到 Debian 10。


验证升级的备用方法：



```
root@linuxtechi:~$ cat /etc/*-release
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@linuxtechi:~$
```

### 结束


希望上面的逐步指南为你提供了从 Debian 9（Stretch）简单地升级为 Debian 10（Buster）的所有信息。在评论部分，请给予你使用 Debian 10 的反馈、建议、体验。




---


via: <https://www.linuxtechi.com/upgrade-debian-9-to-debian-10-command-line/>


作者：[Pradeep Kumar](https://www.linuxtechi.com/author/pradeep/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[robsean](https://github.com/robsean) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
Hello All!!!, Good to See you! So we saw how to install [Debian 10(Buster)](https://www.linuxtechi.com/debian-10-buster-installation-guide/) in the previous article. Today, we are going to learn how to upgrade from Debian 9 to Debian 10. Since we have already seen about Debian 10 and its features, let’s not go deep into it. But readers who didn’t have the chance to read that article, let’s give a quick update about Debian 10 and its new features.

After almost two years of development, the team at Debian has finally released a stable version of Buster, code name for Debian 10. Buster is a LTS (Long Term Support) version and hence will be supported for the next 5 years by Debian.

#### Debian 10 (Buster) – New Features

Debian 10 (Buster) comes packed with a lot of new features which could be rewarding to most of the Debian fans out there. Some of the features include:

- GNOME Desktop 3.30
- AppArmor enabled by default
- Supports Linux Kernel 4.19.0-4
- Supports OpenJDk 11.0
- Moved from Nodejs 4-8 to Nodejs 10.15.2
- Iptables replaced by NFTables

and a lot more.

#### Step by Step Guide to Upgrade from Debian 9 to Debian 10

Before we start upgrading to Debian 10, let’s look at the prerequisites needed for the upgrade:

#### Step 1) Debian upgrade prerequisites

- A good internet connection
- Root user permission
- Data backup

It is extremely important to backup all your application code bases, data files, user account details, configuration files, so that you can always revert to the previous version if anything goes wrong during the upgrade.

#### Step 2) Upgrade Debian 9 Existing Packages

Next step is to upgrade all your existing packages as any packages that are tagged as held back cannot be upgraded and there is a possibility the upgrade from Debian 9 to Debian 10 may fail or cause some issues. So, let’s not take any chances and better upgrade the packages. Use the following code to upgrade the packages:

pkumar@linuxtechi:~$ sudo apt update && sudo apt upgrade -y

#### Step 3) Modify Package Repository file (/etc/sources.list)

Next step is to modify package repository file “/etc/sources.list” where you need to replace the text “Stretch” with the text “Buster”.

But before you change anything, make sure to create a backup of the sources.list file as shown below:

pkumar@linuxtechi:~$ sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

Now use below sed commands to replace the text ‘**stretch**‘ with ‘**buster**‘ in package repository file, example is shown below,

pkumar@linuxtechi:~$ sudo sed -i 's/stretch/buster/g' /etc/apt/sources.list pkumar@linuxtechi:~$ sudo sed -i 's/stretch/buster/g' /etc/apt/sources.list.d/*.list

Once the text is updated, you need to update the package index like shown below:

pkumar@linuxtechi:~$ sudo apt update

Before start upgrading your existing Debian OS , let’s verify the current version using the following command,

pkumar@linuxtechi:~$ cat /etc/*-release PRETTY_NAME="Debian GNU/Linux 9 (stretch)" NAME="Debian GNU/Linux" VERSION_ID="9" VERSION="9 (stretch)" ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/" pkumar@linuxtechi:~$

#### Step 4) Upgrade from Debian 9 to Debian 10

Once you made all the changes, it is time to upgrade from Debian 9 – Debian 10. But before that, make sure to update your packages again as shown below:

pkumar@linuxtechi:~$ sudo apt update && sudo apt upgrade -y

During packages upgrade you will be prompted to start the services, so choose your preferred option

Once all the packages are updated in your system, it is time to upgrade your distribution package. Use the following code to upgrade the distribution:

pkumar@linuxtechi:~$ sudo apt dist-upgrade -y

The upgrade process may take a few minutes depending upon your internet connection. Remember during the upgrade process, you’ll also be asked a few questions whether you need to restart the services during the packages are upgraded and whether you need to keep the existing configurations files. If you don’t want to make any custom changes, simply type “Y” and let the upgrade process continue.

#### Step 5) Verify Upgrade

Once the upgrade process is completed, reboot your machine and check the version using the following command:

pkumar@linuxtechi:~$ lsb_release -a

If you get the output as shown below:

Distributor ID: Debian Description: Debian GNU/Linux 10 (buster) Release: 10 Codename: buster pkumar@linuxtechi:~$

Yes, you have successfully upgraded from Debian 9 to Debian 10.

Alternate way to verify upgrade

pkumar@linuxtechi:~$ cat /etc/*-release PRETTY_NAME="Debian GNU/Linux 10 (buster)" NAME="Debian GNU/Linux" VERSION_ID="10" VERSION="10 (buster)" VERSION_CODENAME=buster ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/" pkumar@linuxtechi:~$

#### Conclusion

Hope the above step by step guide provided you with all the information needed to upgrade from Debian 9(Stretch) to Debian 10 (Buster) easily. Please give us your feedback, suggestions and your experiences with the all new Debian 10 in the comments section. For more such Linux tutorials and articles, keep visiting LinuxTechi.com every now and then.