如何升级到Ubuntu22.04JammyJellyfish

来自菜鸟教程
跳转至:导航、​搜索

介绍

Ubuntu 操作系统的最新长期支持 (LTS) 版本 Ubuntu 20.04 (Jammy Jellyfish) 于 2022 年 4 月 21 日发布。 本指南将说明如何将 20.04 或更高版本的 Ubuntu 系统升级到 Ubuntu 22.04。

警告: 与操作系统的主要版本之间的几乎所有升级一样,此过程存在失败、数据丢失或软件配置损坏的固有风险。 强烈建议进行全面备份和广泛测试

为避免这些问题,我们建议迁移到新的 Ubuntu 22.04 服务器,而不是就地升级。 升级时您可能仍需要查看软件配置的差异,但核心系统可能会具有更高的稳定性。 您可以关注我们的如何迁移到新的Linux服务器系列,学习如何在服务器之间迁移。


先决条件

本指南假定您有一个 Ubuntu 20.04 或更高版本的系统,并配置了启用 sudo 的非 root 用户。

潜在的陷阱

尽管许多系统可以就地升级而不会发生意外,但通过从头开始安装发行版、通过仔细测试配置服务以及将应用程序或用户数据作为单独的迁移来迁移到主要的新版本通常更安全、更可预测步。

如果没有先在暂存环境中针对升级测试所有部署的软件和服务,则永远不要升级生产系统。 请记住,库、语言和系统服务可能已经发生了重大变化。 在升级之前,请考虑阅读 Jammy Jellyfish 发行说明

第 1 步 – 备份您的系统

在尝试对任何系统进行重大升级之前,您应该确保在升级出错时不会丢失数据。 完成此操作的最佳方法是备份整个文件系统。 如果做不到这一点,请确保您拥有用户主目录、任何自定义配置文件以及由关系数据库等服务存储的数据的副本。

在 DigitalOcean Droplet 上,一种方法是关闭系统并拍摄快照(关闭电源可确保文件系统更加一致)。 有关快照过程的更多详细信息,请参阅 如何创建液滴的快照 。 在您确认 Ubuntu 更新成功后,您可以删除快照,这样您就不再需要为其存储付费。

对于适用于大多数 Ubuntu 系统的备份方法,请参阅 如何为您的 VPS 选择有效的备份策略。

第 2 步 – 更新当前安装的软件包

在开始版本升级之前,将当前版本 的所有软件包 更新到最新版本是最安全的。 首先更新软件包列表:

sudo apt update

接下来,将已安装的软件包升级到最新的可用版本:

sudo apt upgrade

您将看到一个升级列表,并提示您继续。 按 y 确认并按 Enter

此过程可能需要一些时间。 完成后,将 dist-upgrade 命令与 apt-get 一起使用,这将执行涉及更改依赖项、根据需要添加或删除新软件包的任何其他升级。 这将处理一组升级,这些升级可能被前面的 apt upgrade 步骤阻止:

sudo apt dist-upgrade

同样,在提示继续时回答 y,然后等待升级完成。

现在您已经安装了最新的 Ubuntu,您可以使用 do-release-upgrade 升级到 22.04 版本。

第 3 步 – 使用 Ubuntu 的 do-release-upgrade 工具进行升级

传统上,Ubuntu 版本可以通过更改 Apt 的 /etc/apt/sources.list(指定软件包存储库)并使用 apt-get dist-upgrade 自行执行升级来进行升级。 尽管此过程仍然可能有效,但 Ubuntu 提供了一个名为 do-release-upgrade 的工具,以使升级更安全、更容易。

do-release-upgrade 处理检查新版本、更新 sources.list 和一系列其他任务,并且是官方推荐的升级路径,用于必须通过远程连接执行的服务器升级。

首先运行 do-release-upgrade 不带任何选项:

sudo do-release-upgrade

如果新的 Ubuntu 版本还没有正式发布,你可能会得到如下输出:

OutputChecking for a new Ubuntu release
No new release found

请注意,在 Ubuntu Server 上,新的 LTS 版本在其第一个 点版本 (在本例中为 22.04.1)之前无法提供给 do-release-upgrade。 这通常是在初始发布日期之后的几个月。

如果您没有看到可用的版本,请添加 -d 选项以升级到 development 版本:

sudo do-release-upgrade -d

如果您通过 SSH 连接到系统,系统会询问您是否要继续。 对于虚拟机或托管服务器,您应该记住失去 SSH 连接是一种风险,特别是如果您没有其他远程连接到系统控制台的方法(例如基于 Web 的控制台功能)。

对于您控制的其他系统,请记住只有在您可以直接物理访问机器时执行主要操作系统升级是最安全的。

在提示符下,输入 y 并按 Enter 继续:

OutputReading cache

Checking package manager

Continue running under SSH?

This session appears to be running under ssh. It is not recommended
to perform a upgrade over ssh currently because in case of failure it
is harder to recover.

If you continue, an additional ssh daemon will be started at port
'1022'.
Do you want to continue?

Continue [yN]

接下来,您将被告知 do-release-upgrade 正在端口 1022 上启动 sshd 的新实例:

OutputStarting additional sshd

To make recovery in case of failure easier, an additional sshd will
be started on port '1022'. If anything goes wrong with the running
ssh you can still connect to the additional one.
If you run a firewall, you may need to temporarily open this port. As
this is potentially dangerous it's not done automatically. You can
open the port with e.g.:
'iptables -I INPUT -p tcp --dport 1022 -j ACCEPT'

To continue please press [ENTER]

Enter。 接下来,您可能会收到未找到镜像条目的警告。 在 DigitalOcean 系统上,忽略此警告并继续升级是安全的,因为 22.04 的本地镜像实际上是可用的。 输入y

OutputUpdating repository information

No valid mirror found

While scanning your repository information no mirror entry for the
upgrade was found. This can happen if you run an internal mirror or
if the mirror information is out of date.

Do you want to rewrite your 'sources.list' file anyway? If you choose
'Yes' here it will update all 'focal' to 'jammy' entries.
If you select 'No' the upgrade will cancel.

Continue [yN]

下载新软件包列表并计算更改后,系统会询问您是否要开始升级。 再次输入 y 继续:

OutputDo you want to start the upgrade?


4 packages are going to be removed. 107 new packages are going to be
installed. 554 packages are going to be upgraded.

You have to download a total of 547 M. This download will take about
1 minute with a 40Mbit connection and about 14 minutes with a 5Mbit
connection.

Fetching and installing the upgrade can take several hours. Once the
download has finished, the process cannot be canceled.

 Continue [yN]  Details [d]

您可能会收到另一个关于无法禁用锁定屏幕的警告:

OutputUnable to disable lock screen

It is highly recommended that the lock screen be disabled during the
upgrade to prevent later issues. Please ensure your screen lock is
disabled before continuing.

如果您连接的是 Ubuntu 服务器而不是桌面,您可以通过按 Enter 忽略此警告。

现在将检索、解压缩和安装新包。 即使您的系统处于快速连接状态,这也需要一段时间。

在安装过程中,您可能会看到有关各种问题的交互式对话框。 例如,可能会询问您是否要在需要时自动重新启动服务:

在这种情况下,回答 Yes 是安全的。 在其他情况下,可能会询问您是否要替换已修改的配置文件。 这通常是一个判断要求,并且可能需要有关本教程范围之外的特定软件的知识。

新软件包安装完成后,系统会询问您是否准备好删除过时的软件包。 在没有自定义配置的库存系统上,在这里输入 y 应该是安全的。 在您已大量修改的系统上,您可能希望输入 d 并检查要删除的软件包列表,以防它包含您以后需要重新安装的任何内容。

OutputRemove obsolete packages?


53 packages are going to be removed.

 Continue [yN]  Details [d]

最后,假设一切顺利,您将被告知升级已完成,需要重新启动。 输入 y 继续:

OutputSystem upgrade is complete.

Restart required

To finish the upgrade, a restart is required.
If you select 'y' the system will be restarted.

Continue [yN]

在 SSH 会话中,您可能会看到如下内容:

OutputConnection to 203.0.113.241 closed by remote host.
Connection to 203.0.113.241 closed.

您可能需要在此处按一个键退出到本地提示,因为您的 SSH 会话将在服务器端终止。

等待您的服务器重新启动,然后重新连接。 登录时,您应该会收到一条消息,确认您现在在 Focal Fossa 上:

OutputWelcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-25-generic x86_64)

结论

你现在应该有一个工作的 Ubuntu 22.04 安装。 从这里开始,您可能需要调查对服务和部署的应用程序进行必要的配置更改。

您可以在我们的 Ubuntu 22.04 教程标签页 上找到更多 22.04 教程和问题。