如何升级到 Ubuntu 16.04 LTS
介绍
警告:与操作系统主要版本之间的几乎所有升级一样,此过程存在失败、数据丢失或软件配置损坏的固有风险。强烈建议进行全面备份和广泛测试。
为避免这些问题,我们建议尽可能迁移到新的 Ubuntu 16.04 服务器,而不是就地升级。升级时您可能仍需要查看软件配置的差异,但核心系统可能会具有更高的稳定性。您可以按照我们关于如何迁移到新 Linux 服务器的系列文章来了解如何在服务器之间迁移。
Ubuntu 操作系统的下一个长期支持版本 16.04 (Xenial Xerus) 将于 2016 年 4 月 21 日发布。
虽然在撰写本文时尚未发布,但已经可以将 15.10 系统升级到 16.04 的开发版本。这可能有助于在正式发布日期之前测试升级过程和 16.04 本身的功能。
本指南将解释系统的过程,包括(但不限于)运行 Ubuntu 15.10 的 DigitalOcean Droplets。
先决条件
本指南假设您有一个运行 Ubuntu 15.10 的系统,并配置了一个具有 sudo
管理任务权限的非根用户。
潜在的陷阱
尽管许多系统可以就地升级而不会发生意外,但通过从头开始安装发行版、通过仔细测试配置服务以及将应用程序或用户数据作为单独的应用程序迁移到一个主要的新版本,迁移到一个主要的新版本通常更安全、更可预测。步。
如果没有首先在暂存环境中针对升级测试所有已部署的软件和服务,则永远不要升级生产系统。请记住,库、语言和系统服务可能已经发生了重大变化。在 Ubuntu 16.04 中,自上一个 LTS 版本以来的重要变化包括过渡到 systemd init 系统代替 Upstart,强调对 Python 3 的支持,以及 PHP 7 代替 PHP 5。
在升级之前,请考虑阅读 Xenial Xerus 发行说明。
第 1 步 – 备份您的系统
在尝试对任何系统进行重大升级之前,您应该确保如果升级出错不会丢失数据。完成此操作的最佳方法是备份整个文件系统。如果做不到这一点,请确保您拥有用户主目录、任何自定义配置文件以及关系数据库等服务存储的数据的副本。
在 DigitalOcean Droplet 上,最简单的方法是关闭系统并拍摄快照(关闭电源可确保文件系统更加一致)。有关快照过程的更多详细信息,请参阅如何使用 DigitalOcean 快照自动备份您的 Droplet。当您确认更新成功后,您可以删除快照,这样您就不会再为此付费。
对于适用于大多数 Ubuntu 系统的备份方法,请参阅如何为您的 VPS 选择有效的备份策略。
第 2 步 – 升级当前安装的软件包
在开始版本升级之前,最安全的做法是为当前版本安装所有包的最新版本。首先更新包列表:
- sudo apt-get update
接下来,将已安装的软件包升级到最新的可用版本:
- sudo apt-get upgrade
您将看到升级列表,并提示您继续。回答 y 表示是,然后按 Enter。
此过程可能需要一些时间。完成后,使用 dist-upgrade
命令,该命令将执行升级,包括更改依赖项、根据需要添加或删除新包。这将处理一组可能被 apt-get upgrade
阻止的升级:
- sudo apt-get dist-upgrade
同样,在提示继续时回答 y,并等待升级完成。
现在您已经安装了最新的 Ubuntu 15.10,您可以使用 do-release-upgrade
升级到 16.04 版本。
第 3 步 – 使用 Ubuntu 的 do-release-upgrade 工具执行升级
首先,确保安装了 update-manager-core
包:
- sudo apt-get install update-manager-core
传统上,Debian 版本可以通过更改 Apt 的 /etc/apt/sources.list
来升级,它指定了包存储库,并使用 apt-get dist-upgrade
来执行升级本身。 Ubuntu 仍然是 Debian 派生的发行版,因此这个过程可能仍然有效。然而,我们将使用 do-release-upgrade
,这是 Ubuntu 项目提供的一个工具,它负责检查新版本、更新 sources.list
,以及一系列其他任务。这是官方推荐的服务器升级升级路径,必须通过远程连接执行。
从不带任何选项运行 do-release-upgrade
开始:
- sudo do-release-upgrade
如果 Ubuntu 16.04 尚未发布,您应该会看到以下内容:
Checking for a new Ubuntu release
No new release found
为了在正式发布之前升级到 16.04,请指定 -d
选项以使用 development 版本:
- sudo do-release-upgrade -d
如果您通过 SSH 连接到您的系统,就像 DigitalOcean Droplet 一样,系统会询问您是否要继续。
在 Droplet 上,通过 SSH 升级是安全的。虽然 do-upgrade-release
没有通知我们这件事,但您可以使用 DigitalOcean 控制面板中可用的控制台连接到您的 Droplet,而无需运行 SSH。
对于由其他提供商托管的虚拟机或托管服务器,您应该牢记失去 SSH 连接是一种风险,尤其是当您没有其他方法远程连接到系统控制台时。对于您控制的其他系统,请记住只有在您可以直接物理访问计算机时才执行主要操作系统升级是最安全的。
在提示符下,键入 y 并按 Enter 键继续:
Reading 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] y
接下来,您将被告知 do-release-upgrade
正在端口 1022 上启动一个新的 sshd
实例:
Starting 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]
按回车。接下来,可能会警告您找不到镜像条目。在 DigitalOcean 系统上,忽略此警告并继续升级是安全的,因为 16.04 的本地镜像实际上可用。输入 y:
Updating 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 'trusty' to 'xenial' entries.
If you select 'No' the upgrade will cancel.
Continue [yN] y
下载新包列表并计算更改后,系统会询问您是否要开始升级。再次输入 y 继续:
Do you want to start the upgrade?
6 installed packages are no longer supported by Canonical. You can
still get support from the community.
9 packages are going to be removed. 104 new packages are going to be
installed. 399 packages are going to be upgraded.
You have to download a total of 232 M. This download will take about
46 seconds with your connection.
Installing the upgrade can take several hours. Once the download has
finished, the process cannot be canceled.
Continue [yN] Details [d]y
现在将检索新软件包,然后解压缩并安装。即使您的系统连接速度很快,这也需要一段时间。
在安装过程中,您可能会看到各种问题的交互式对话框。例如,系统可能会询问您是否要在需要时自动重启服务:

在这种情况下,回答“是”是安全的。在其他情况下,系统可能会询问您是否希望将已修改的配置文件替换为正在安装的软件包中的默认版本。这通常是判断调用,并且可能需要有关本教程范围之外的特定软件的知识。
新包安装完成后,系统会询问您是否准备好删除过时的包。在没有自定义配置的库存系统上,在这里输入 y 应该是安全的。在你修改过的系统上,你可能希望输入 d 并检查要删除的包列表,以防它包含你以后需要重新安装的任何东西。
Remove obsolete packages?
53 packages are going to be removed.
Continue [yN] Details [d]y
最后,假设一切顺利,您将被告知升级已完成并且需要重新启动。输入 y 继续:
System upgrade is complete.
Restart required
To finish the upgrade, a restart is required.
If you select 'y' the system will be restarted.
Continue [yN] y
在 SSH 会话中,您可能会看到如下内容:
=== Command detached from window (Thu Apr 7 13:13:33 2016) ===
=== Command terminated normally (Thu Apr 7 13:13:43 2016) ===
您可能需要在此处按一个键退出到本地提示,因为您的 SSH 会话将在服务器端终止。稍等片刻,让您的系统重新启动,然后重新连接。登录时,您应该会收到一条消息,确认您现在正在使用 Xenial Xerus:
Welcome to Ubuntu Xenial Xerus (development branch) (GNU/Linux 4.4.0-17-generic x86_64)
结论
您现在应该可以正常安装 Ubuntu 16.04。从这里开始,您可能需要调查对服务和已部署应用程序的必要配置更改。在接下来的几周内,我们将开始发布特定于 Ubuntu 16.04 的 DigitalOcean 指南,涵盖广泛的主题。