初级：如何在终端及图形界面中更新 Ubuntu
Ubuntu 升级 更新

> 
> 这篇教程将向你展示如何更新服务器版本或者桌面版本的 Ubuntu。它还解释了更新和升级之间的区别以及你应该了解的有关于 Ubuntu Linux 中的更新的一些其他内容。
> 
> 
> 


如果你是一个新手并已经体验 Ubuntu 数天或几周，你可能想知道如何更新你的 [Ubuntu](https://www.ubuntu.com/) 系统以获取安全补丁，错误修复和应用升级。


更新 Ubuntu 非常简单。我并不是瞎说。它简单得只要运行两个命令。让我来告诉你这两个命令的更多细节。


请注意，本教程适用于 Ubuntu 18.04、16.04 或任何其他版本。命令行方式也适用于基于 Ubuntu 的发行版如 Linux Mint、Linux Lite、elementary OS 等。


### 通过命令行更新 Ubuntu


![如何更新 Ubuntu](/data/attachment/album/201901/01/212906rhz7lwatjcha74a4.png)


在桌面上，打开终端。你可以在菜单里找到它或者使用 `Ctrl+Alt+T` [快捷键](https://itsfoss.com/ubuntu-shortcuts/)。如果你是登录到一台 [Ubuntu 服务器](https://www.ubuntu.com/download/server)，那你已经在访问一个终端了。


在终端里，你只需要使用以下命令：



```
sudo apt update && sudo apt upgrade -y
```

它将询问你密码，而你可以使用你的账号密码。输入时，你将不会看到任何内容在屏幕上，所以请继续输入你的密码并按回车键。


现在，我来解释下上面的命令。


事实上，这不是一条命令。它由两条命令组成。符号 `&&` 是合并两条命令的一个方法，第二条命令仅在前一条命令执行成功时执行。


当命令 `apt upgrade` 要求你在安装更新前确认时，末尾的参数 `-y` 会自动输入 `yes`。


请注意，你也可以逐条使用这两条命令：



```
sudo apt update
sudo apt upgrade
```

这将花费更长的时间，因为你必须等待第一条命令执行完成后才能输入第二条命令。


#### 说明：sudo apt update


这条命令更新了可用软件包的本地数据库。如果你没运行这条命令，本地数据库将不会被更新，而你的系统将不会知道是否有可用的新版本。


这就是为什么当你运行 `sudo apt update`，你会在输出中看到大量的 URL。这条命令会从对应的储存库（你在输出中看到的 URL）中获取软件包信息。


![更新 Ubuntu Linux](/data/attachment/album/201901/01/212909g6gvtguhe3oehv61.jpg)


在命令的末尾，它告诉你有多少个软件包可以被更新。你可以使用下列命令查看这些软件包：



```
apt list --upgradable
```

**补充阅读：** 阅读这篇文章了解[命令 apt update 的输出中的 Ign、Hit 和 Get 是什么](https://itsfoss.com/apt-get-linux-guide/)。


#### 说明：sudo apt upgrade


这条命令将已安装的软件包版本与本地数据库进行匹配。它收集全部信息，然后列出所有具有更新版本的软件包。此时，它会询问您是否要升级（已安装的软件包更新到新版本）。


![通过命令行更新 Ubuntu Linux](/data/attachment/album/201901/01/212911vntw1ri1rmoloieo.jpg)


你可以键入 `yes`、`y` 或者只敲回车键去确认安装这些更新。


所以总的来说，`sudo apt update` 会检查可用的新版本，而 `sudo apt upgrade` 实际上会执行更新。


命令 `update` 可能会令人困惑，因为你可能期望通过命令 `apt update` 安装更新来更新系统，但这并不会发生。


### 通过 GUI 更新 Ubuntu（适用于桌面用户）


如果你使用桌面版 Ubuntu，你并不需要为了更新系统而打开终端。你可以仍可以使用命令行更新，但这只是一个选择。


在菜单里，找到 “软件更新” 并运行它。


![在 Ubuntu 中运行 Software Updater](/data/attachment/album/201901/01/212912wsnuxosqxe7yoqx4.jpg)


它将检查你的系统是否有可用的更新。


![检查 Ubuntu 是否有可用更新](/data/attachment/album/201901/01/212913tn59x0ycxsnxwyyh.jpg)


如果有可用的更新，它将给你提供安装更新的选择。


![在 Ubuntu 中通过更新管理器安装更新](/data/attachment/album/201901/01/212914f4d5w10me3em1t9d.jpg)


现在，点击 “安装”，它可能会向你询问密码。


![通过 GUI 在 Ubuntu Linux 中安装更新](/data/attachment/album/201901/01/212915raja5770fs9j7acj.jpg)


一旦你输入你的密码，它将开始安装更新。


![通过 GUI 更新 Ubuntu](/data/attachment/album/201901/01/212916g38aboo33oouov73.jpg)


在某些情况下，你可能需要重启系统才能使已安装的更新正常工作。如果需要重启系统，你将在更新结束时收到通知。


![通过 GUI 更新 Ubuntu](/data/attachment/album/201901/01/212916g38aboo33oouov73.jpg)


如果你不希望马上重启你的系统，可以选择稍后重启。


![通过 GUI 在 Ubuntu 中安装更新](/data/attachment/album/201901/01/212916j1qkarloaxxfl1te.jpg)


提示：如果“软件更新”返回一个错误，你需要在终端是使用命令 `sudo apt update`。输出的最后几行将包含真正的错误信息。你可以在因特网上搜索该错误并解决问题。


### 更新 Ubuntu 时要记住几件事


你刚学习了如何更新你的 Ubuntu 系统。如果你感兴趣，你还需要了解一些关于 Ubuntu 更新的内容。


#### 更新后清理


你的系统将会有一些更新后不再需要的软件包。你可用使用这条命令删除这些软件包并[释放空间](https://itsfoss.com/free-up-space-ubuntu-linux/)：



```
sudo apt autoremove
```

#### 在 Ubuntu Server 中内核热修复以避免重启


如果是 Linux 内核更新，你将需要在系统更新后重启。当你不希望服务器停机时，这将会是一个问题。


[热修复](https://www.ubuntu.com/livepatch)功能允许 Linux 内核在持续运行时打补丁。换句话说就是你不需要重启你的系统。


如果你在管理服务器，你可能需要[在 Ubuntu 中启用热修复](https://www.cyberciti.biz/faq/howto-live-patch-ubuntu-linux-server-kernel-without-rebooting/)。


#### 版本升级是不同的


本文讨论的更新是使你安装的 Ubuntu 保持最新。但它不包括[版本升级](https://itsfoss.com/upgrade-ubuntu-version/)（例如从 Ubuntu 16.04 升级到 18.04）。


[Ubuntu 版本](https://itsfoss.com/how-to-know-ubuntu-unity-version/) 升级完全是另一回事。它更新整个操作系统核心。你需要在这个漫长的过程开始前做好备份。


### 总结


我希望你喜欢这个关于 Ubuntu 系统更新的教程并学到一些新东西。


如果你有其他问题，请随时提出。如果你是一位经验丰富的 Linux 用户并且有些更好的技巧，请同我们分享。




---


via: <https://itsfoss.com/update-ubuntu/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[LazyWolfLin](https://github.com/LazyWolfLin) 校对：[wxy](https://github.com/wxy)


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


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

If you are a new user and have been using Ubuntu for a few days or weeks, you might be wondering how to update your [Ubuntu](https://www.ubuntu.com/?ref=itsfoss.com) system for security patches, bug fixes and application upgrades.

Updating Ubuntu is incredibly simple. I am not exaggerating. It’s as simple as running two commands:

```
sudo apt update
sudo apt upgrade
```


Actually, there are two ways you can update your Ubuntu system:

- Update Ubuntu via the command line
- Update Ubuntu using the Software Updater GUI tool

Let me give you more details. Please note that this tutorial is valid for Ubuntu 20.04, 22.04, or any other version. The command line method is also valid for Ubuntu-based Linux distributions, like Linux Mint, Linux Lite, elementary OS, etc.

[upgrading Ubuntu version](https://itsfoss.com/upgrade-ubuntu-version/).

## Method 1: Update Ubuntu via the Command Line

First, [open the terminal in Ubuntu desktop](https://itsfoss.com/open-terminal-ubuntu/). You can find it in the menu, or use the Ctrl+Alt+T [keyboard shortcut](https://itsfoss.com/ubuntu-shortcuts/). If you are logged on to an [Ubuntu server](https://www.ubuntu.com/download/server?ref=itsfoss.com), you already have access to a terminal.

In the terminal, you have to use the following command:

`sudo apt update && sudo apt upgrade -y`


**, so keep on typing your password and hit enter. This will update the packages in Ubuntu.**

*You won’t see characters on the screen while typing the password in the terminal*![Updating Ubuntu](https://itsfoss.com/content/images/2023/07/update-ubuntu-single-command.png)

See, how easy it is to update Ubuntu from the terminal? Now let me explain the above command.

It’s actually not a single command; it’s a combination of two commands. The && is a way to [run multiple commands in Linux](https://itsfoss.com/run-multiple-commands-linux/) in a way such that the second command runs only when the previous command ran successfully.

**The “-y” in the end automatically enters “yes” when the command “apt upgrade” ask for your confirmation before installing updates.**

Note that you can also use the two commands separately, one by one:

```
sudo apt update
sudo apt upgrade
```


It will take a little longer because you have to wait for one command to finish and then enter the second command.

**More than just OS updates**: Unlike Windows,

[Linux works with a package manager](https://itsfoss.com/package-manager/). When you run the updates, it updates all the packages installed via apt. This means updating Ubuntu will update the core operating system, Linux kernels, and the applications installed from the software center (if they were apt packages) or installed using apt command.

### Explanation: sudo apt update

This command updates the local database of available packages. If you don’t run this command, the local database won’t be updated and your system will not know if there are any new versions of packages available.

This is why, when you run the “sudo apt update” command, you’ll see lots of URLs in the output. The command fetches the package information from the respective repositories (the URLs you see in the output).

![Updating Ubuntu Linux](https://itsfoss.com/content/images/wordpress/2018/12/update-ubunt-1-800x357.jpeg)

At the end of the command, it tells you how many packages can be upgraded. You can see these packages by running the following command:

`apt list --upgradable`


### Explanation: sudo apt upgrade

This command matches the versions of installed packages with the local database. It collects all of them, and then it will list those packages that have a newer version available. At this point, it will ask if you want to upgrade the installed packages to the newer version.

![Update Ubuntu Linux via Command Line](https://itsfoss.com/content/images/wordpress/2018/12/update-ubunt-2.jpeg)

You can type “yes,” or “y,” or just press enter to confirm the installation of updates.

So the bottom line is that “sudo apt update” checks for the availability of new package versions, while “sudo apt upgrade” actually installs the new versions.

The term update might be confusing, as you might expect the “apt update” command to update the system by installing new software, but that’s not how it works.

## Method 2: Update Ubuntu via the GUI [For Desktop Users]

If you are using Ubuntu as a desktop, you don’t have to go to the terminal to update the system. You can still use the command line, but it’s optional for you.

In the menu, look for “Software Updater” and run it.

![Run Software Updater in Ubuntu](https://itsfoss.com/content/images/wordpress/2018/12/update-ubuntu-via-GUI-1-800x250.jpeg)

It will check if there are updates available for your system.

![Checking if updates are available for Ubuntu](https://itsfoss.com/content/images/wordpress/2018/12/update-ubuntu-via-GUI-2-800x250.jpeg)

If there are updates available, it will give you the option to install the updates.

![Install Updates via Update Manager in Ubuntu](https://itsfoss.com/content/images/wordpress/2018/12/update-ubuntu-GUI-3-800x365.jpeg)

Click on “Install Now.” It may ask for your password.

![Installing Updates in Ubuntu Linux via GUI](https://itsfoss.com/content/images/wordpress/2018/12/install-update-ubuntu-1-800x450.jpg)

Once you enter your password, it will start installing the updates.

![Updating Ubuntu via GUI](https://itsfoss.com/content/images/wordpress/2018/12/installing-updates-ubuntu.jpg)

In some cases, you may need to [reboot your Ubuntu system](https://itsfoss.com/schedule-shutdown-ubuntu/) for the installed updates to work properly. You’ll be notified at the end of the update if you need to restart the system.

![Updating Ubuntu via GUI](https://itsfoss.com/content/images/wordpress/2018/12/installing-updates-ubuntu.jpg)

You can choose to restart later if you don’t want to reboot your system straightaway.

![Installing updates via GUI in Ubuntu](https://itsfoss.com/content/images/wordpress/2018/12/installing-updates-ubuntu-2.jpeg)

Tip: If the software updater returns an error, you should use the command “sudo apt update” in the terminal. The last few lines of the output will contain the actual error message. You can then search on the internet for that error and fix the problem.

## A few things to keep in mind about updating Ubuntu

You just learned how to update your Ubuntu system. If you are interested, you should also know these few things relating to Ubuntu updates.

### Cleaning up after an update

After an update, your system may have some unnecessary packages that are no longer required. You can remove such packages and [free up some space](https://itsfoss.com/free-up-space-ubuntu-linux/) by using this command:

`sudo apt autoremove`


### Live patching the kernel in Ubuntu Server to avoid rebooting

In the case of Linux kernel updates, you’ll have to restart the system after the update. This can be a problem if you don’t want downtime for your server.

The [live patching](https://www.ubuntu.com/livepatch?ref=itsfoss.com) feature allows for the patching of the Linux kernel while it is still running. In other words, you don’t have to reboot your system.

If you manage servers, you may want to [enable live patching in Ubuntu](https://www.cyberciti.biz/faq/howto-live-patch-ubuntu-linux-server-kernel-without-rebooting/?ref=itsfoss.com).

### Ubuntu version upgrades are different from package upgrades

The update methods discussed here keep your Ubuntu install fresh and updated. It doesn’t cover OS [version upgrades](https://itsfoss.com/upgrade-ubuntu-version/) (for example, upgrading Ubuntu 16.04 to 18.04).

[Ubuntu version](https://itsfoss.com/how-to-know-ubuntu-unity-version/) upgrades are an entirely different thing. They involve updating the entire operating system core. You’ll need to make proper backups before starting this lengthy process.

## Conclusion

I hope you liked this tutorial on updating the Ubuntu system and that you learned a few new things.

If you have any questions, please feel free to ask. If you are an experienced Linux user and have some tips that can make this tutorial more useful, please share them with the rest of us.