apt 的 update 和 upgrade 命令的区别是什么？
apt
![](/data/attachment/album/202209/02/224416uecz5x75yalc0axc.jpg)


如果想让你的 Ubuntu 或者 Debian 系统保持更新，要用 `sudo apt update` 和 `sudo apt upgrade` 命令组合。


一些以前的教程也会提到 `sudo apt-get update` 和 `sudo apt-get upgrade`。


`apt` 和 `apt-get` 命令运行起来几乎一样，除了一些细微的差别，后面我会讨论。


我们首先讨论一下 `update` 和 `upgrade` 的区别。这两个难道不是一样的吗？


### apt 的 update 和 upgrade 的区别


尽管听上去运行 `apt update` 可以给你一个包的最新版本，然而这并不正确。`update` 命令只会获得系统上所有包的最新信息，并不会下载或者安装任何一个包。而是 `apt upgrade` 命令来把这些包下载和升级到最新版本。


还是有点困惑？让我来接着解释。我建议阅读 [包管理器的概念](https://itsfoss.com/package-manager/)。这个会帮你更好的理解这些东西。


![Linux Package Manager Explanation](/data/attachment/album/202209/02/224431u1mrghgrhmnxgrnz.png)


基本上，你的系统围绕着一个所有可用包的数据库（缓存）工作。注意，这个缓存（或者数据库）并不包含这些包本身，仅仅是关于包的元数据（版本、仓库、依赖等）。


如果你不更新这个数据库，系统就不会知道是否有更新的版本。


当你运行 `apt update` 或者 `apt-get update` 命令，它会获取这些包的最新元数据（包的版本等）。


![apt update](/data/attachment/album/202209/02/224431rvuvxugm6vwkmwcg.png)


这时候本地缓存就被更新了，有一些包可以升级。用 `sudo apt upgrade` 可以升级所有（可升级的）包。


它会显示要升级的包，并且通过回车（默认选择是 `Y`）或者按下 `Y` 键进行确认。要在这个阶段取消升级，可以按下 `N`。


![apt upgrade](/data/attachment/album/202209/02/224431ttohko0r9thbtujq.png)


下面这些可能会帮助你记忆：


* `apt update`：更新包缓存（可以知道包的哪些版本可以被安装或升级）
* `apt upgrade`：升级包到最新版本


因为有一些管理员命令，需要作为 root 运行。因此需要使用 `sudo` 配合其他命令。`sudo` 使你能够作为 root 在 Ubuntu 和 Debian 上运行命令。


既然理解了 `update` 和 `upgrade` 是如何一起运行的，我们接下来来讨论一下 `apt` 和 `apt-get` 的用法。


### apt 还是 apt-get？应该用哪个？


Debian 和 Ubuntu 使用的是 APT 包管理系统。不要和 `apt` 命令弄混了。


有许多和 APT 包管理交互的命令；`apt-get`、`apt`、`dpkg`、`aptitude` 等。


这里面最受欢迎的就是 `apt-get` 命令。它是一个<ruby> 低层级 <rt>  low-level </rt></ruby>且功能丰富的命令。`apt` 是 `apt-get` 命令的一个更新而更简单的版本。


可以读一下这篇文章来 [了解 atp 和 apt-get 命令的不同](https://itsfoss.com/apt-get-upgrade-vs-dist-upgrade/)。下面重点讨论这些命令中 `update` 和 `upgrade` 选项的区别。


#### apt update vs apt-get update


`apt-get update` 和 `apt update` 做的是同样的事，都是更新本地包缓存，这样的话你的系统就知道有哪些包的版本是可用的。


从技术上讲，其实并没有区别。然而，`apt update` 在一个方面比 `apt-get update` 做的好，**它会告诉你可升级的包的数量**。



```
Hit:15 https://ppa.launchpadcontent.net/slimbook/slimbook/ubuntu jammy InRelease
Fetched 213 kB in 4s (55.8 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
6 packages can be upgraded. Run 'apt list --upgradable' to see them.

```

`apt-get update` 甚至不会告诉你包是否可以升级。


![apt get update](/data/attachment/album/202209/02/224431rxk3zl0ccaxixt4e.png)


![apt update output](/data/attachment/album/202209/02/224431c3ojf1iu3wq3awjj.png)


从 `apt` 中可以看到 [列出可升级的包](https://itsfoss.com/apt-list-upgradable/)，而 `apt-get` 甚至没有这个选项。



```
# apt list --upgradable
Listing... Done
fprintd/jammy-updates 1.94.2-1ubuntu0.22.04.1 amd64 [upgradable from: 1.94.2-1]
gnome-control-center-data/jammy-updates,jammy-updates 1:41.7-0ubuntu0.22.04.4 all [upgradable from: 1:41.7-0ubuntu0.22.04.1]
gnome-control-center-faces/jammy-updates,jammy-updates 1:41.7-0ubuntu0.22.04.4 all [upgradable from: 1:41.7-0ubuntu0.22.04.1]
gnome-control-center/jammy-updates 1:41.7-0ubuntu0.22.04.4 amd64 [upgradable from: 1:41.7-0ubuntu0.22.04.1]
libpam-fprintd/jammy-updates 1.94.2-1ubuntu0.22.04.1 amd64 [upgradable from: 1.94.2-1]
vivaldi-stable/stable 5.4.2753.40-1 amd64 [upgradable from: 5.4.2753.37-1]

```

现在来比较一下两个命令中 `upgrade` 的选项。


#### apt upgrade vs apt-get upgrade


`apt-get upgrade` 和 `apt upgrade` 命令根据本地包缓存（通过 `update` 命令更新）的数据，安装可升级包的最新版本。


然而，`apt upgrade` 命令会做两件与 `apt-get upgrade` 不同的事情。


`apt upgrade` 命令可以升级 Linux 内核版本，`apt-get upgrade` 不能。`apt-get` 命令需要使用 [apt-get dist-upgrade](https://itsfoss.com/apt-get-upgrade-vs-dist-upgrade/) 来升级内核版本。


![apt-get upgrade command cannot upgrade Linux kernel version](/data/attachment/album/202209/02/224432yfee97tzeffn97ff.png)


这是因为升级内核版本意味着安装一个全新的包。`apt-get upgrade` 命令不能安装一个新的包。它只能升级现有的包。


`apt upgrade` 比 `apt-get` 做的好的另一件小事是，它会在底部**显示一个进度条**。


![apt upgrade progress bar](/data/attachment/album/202209/02/224432nu8ad8hjbafdaccc.png)


### 总结


`update` 和 `upgrade` 两个词很相似，这就是为什么很多新用户会感到困惑。有时候，我觉得 `apt update` 命令应该和 `apt upgrade` 命令合并。


我意思是 `upgrade`（所有已安装的包）和 `update`（本地包元数据缓存）一起完成工作。为什么要有两个分开的命令呢？把这两个领命合成一个 `upgrade` 命令吧。Fedora 就是这样对 DNF 命令进行了改进。不过这只是我的观点。


我希望这篇文章可以解释一些关于 `apt-get update`、`apt-get upgrade` 和 `apt update` 以及 `apt upgrade` 命令的问题。


如果有任何问题，请与我联系。




---


via: <https://itsfoss.com/apt-update-vs-upgrade/>


作者：[Abhishek Prakash](https://itsfoss.com/) 选题：[lkxed](https://github.com/lkxed) 译者：[Yufei-Yan](https://github.com/Yufei-Yan) 校对：[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 want to [keep your Ubuntu system updated](https://itsfoss.com/update-ubuntu/), you use the combination of **sudo apt update** and **sudo apt upgrade** commands.

Some older tutorial also mentions **sudo apt-get update** and **sudo apt-get upgrade**.

Both `apt`

and `apt-get`

commands work pretty much the same except for some minor differences that I’ll discuss later in this tutorial.

Let’s first discuss the difference between *update* and *upgrade*. Aren't the two the same thing?

## Difference between apt update and upgrade

Though it sounds like running the `apt update`

will give you the latest version of the package, it’s not true. The *update* command only gets the information about the latest version of packages available for your system. It doesn’t download or install any package. It is the `apt upgrade`

command that actually downloads and upgrades the package to the new version.

Still confused? Let me explain a bit more. I advise [reading up on the concept of package manager](https://itsfoss.com/package-manager/). It will help you understand things even better.

![Linux Package Manager Explanation](https://itsfoss.com/content/images/wordpress/2020/10/linux-package-manager-explanation.png)

Basically, your system works on a database (cache) of available packages. Note that this cache or database doesn’t contain the packages themselves, just the metadata (version, repository, dependency etc.) on the package.

If you don’t update this database, the system won’t know if there are newer packages available or not.

When you run the **apt update** or **apt-get update** command, it will fetch the updated metadata (package version etc.) on the packages.

![Running apt update command in a terminal](https://itsfoss.com/content/images/wordpress/2022/08/apt-update.png)

Your local package cache has been updated and there are packages that can be upgraded. You can upgrade all the (upgradable) packages with `sudo apt upgrade`

.

It shows the packages that are going to be upgraded and ask you to confirm by pressing enter (for default choice Y) or Y key. To cancel the upgrade at this stage, you can press N.

![Running apt upgrade in a terminal](https://itsfoss.com/content/images/wordpress/2022/08/apt-upgrade.png)

If it helps you remember:

**apt update**: updates the package cache (to know which package versions can be installed or upgraded)**apt upgrade**: upgrades packages to the new version

Since these are administrative commands, you need to run them as root. And hence you use **sudo** with both commands. The sudo part lets you [run commands as root in Ubuntu](https://itsfoss.com/root-user-ubuntu/) and Debian.

Now that you understand how the combination update and upgrade works, let’s discuss the use of apt and apt-get.

## apt or apt-get? Which one should you be using?

Debian and Ubuntu use the APT package management system. Don’t confuse it with the `apt`

command.

There are many [commands that interact with the APT](https://itsfoss.com/apt-command-guide/) package management; apt-get, apt, dpkg, aptitude etc.

The `apt-get`

command was the most popular of them all. It is a low-level, feature rich command. `apt`

is a newer and simpler version of apt-get.

You can [read this article to learn on the differences of apt and apt-get commands](https://itsfoss.com/apt-get-upgrade-vs-dist-upgrade/). Let me focus on the difference between the update and upgrade options of these commands.

### apt update vs apt-get update

Both `apt-get update`

and `apt update`

do the same task of updating the local package cache so that your system is aware of the available package versions.

Technically, there is no difference. However, `apt update`

does one thing better than `apt-get update`

. It **tells you the number of packages that can be upgraded**.

```
Hit:15 https://ppa.launchpadcontent.net/slimbook/slimbook/ubuntu jammy InRelease
Fetched 213 kB in 4s (55.8 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
6 packages can be upgraded. Run 'apt list --upgradable' to see them.
```


`apt-get update`

doesn’t even tell you if any package can be upgraded.

![Running "apt-get update" command and it doesn't show the number of packages that can be upgraded](https://itsfoss.com/content/images/wordpress/2022/08/apt-get-update.png)

You can see the [list of upgradable packages](https://itsfoss.com/apt-list-upgradable/) with `apt`

, but `apt-get`

doesn’t have this option.

```
abhishek@itsfoss:~$ apt list --upgradable
Listing... Done
fprintd/jammy-updates 1.94.2-1ubuntu0.22.04.1 amd64 [upgradable from: 1.94.2-1]
gnome-control-center-data/jammy-updates,jammy-updates 1:41.7-0ubuntu0.22.04.4 all [upgradable from: 1:41.7-0ubuntu0.22.04.1]
gnome-control-center-faces/jammy-updates,jammy-updates 1:41.7-0ubuntu0.22.04.4 all [upgradable from: 1:41.7-0ubuntu0.22.04.1]
gnome-control-center/jammy-updates 1:41.7-0ubuntu0.22.04.4 amd64 [upgradable from: 1:41.7-0ubuntu0.22.04.1]
libpam-fprintd/jammy-updates 1.94.2-1ubuntu0.22.04.1 amd64 [upgradable from: 1.94.2-1]
vivaldi-stable/stable 5.4.2753.40-1 amd64 [upgradable from: 5.4.2753.37-1]
```


Let’s talk compare the upgrade option of both commands.

### apt upgrade vs apt-get upgrade

Both `apt-get upgrade`

and `apt upgrade`

commands install the newer version of the upgradable packages based on the data in the local package cache (refreshed by the update command).

However, the `apt upgrade`

command does a couple of things differently than its `apt-get`

counterpart.

The **apt upgrade command can upgrade the Linux kernel version, apt-get upgrade cannot** do that. You need to use [apt-get dist-upgrade](https://itsfoss.com/apt-get-upgrade-vs-dist-upgrade/) for upgrading the kernel version with apt-get command.

![apt-get upgrade command cannot upgrade Linux kernel version](https://itsfoss.com/content/images/wordpress/2022/08/apt-get-upgrade.png)

`apt-get upgrade`

commandThis is because upgrading the kernel version means installing a completely new package. `apt-get upgrade`

command cannot install a new package. It can only upgrade existing packages.

Another small thing that `apt upgrade`

does better than `apt-get upgrade`

is to **show a progress bar** at the bottom.

![apt upgrade progress bar](https://itsfoss.com/content/images/wordpress/2022/08/apt-upgrade-progress-bar.png)

## Conclusion

Another common confusion is between [upgrade and dist-upgrade](https://itsfoss.com/apt-get-upgrade-vs-dist-upgrade/):

[apt-get upgrade vs dist-upgrade [Difference Explained]The apt-get upgrade and dist-upgrade are both used for upgrading the installed packages. So, what’s the difference?](https://itsfoss.com/apt-get-upgrade-vs-dist-upgrade/)![](https://itsfoss.com/content/images/wordpress/2022/08/apt-get-upgrade-vs-dist-upgrade.png)


![](https://itsfoss.com/content/images/wordpress/2022/08/apt-get-upgrade-vs-dist-upgrade.png)

Learn how to use apt-get commands with this guide:

[Using apt-get Commands in Linux [Ultimate Guide]This beginner’s guide shows you what you can do with apt-get commands in Linux, how to use them to find new packages, install and upgrade new packages, and clean your system.](https://itsfoss.com/apt-get-linux-guide/)![](https://itsfoss.com/content/images/2023/05/apt-get-ultimate-guide.png)


![](https://itsfoss.com/content/images/2023/05/apt-get-ultimate-guide.png)

Similarly, you should also get familiar with the apt commands:

[Using apt Commands in Linux [Ultimate Guide]This guide shows you how to use apt commands in Linux with examples so that you can manage packages effectively.](https://itsfoss.com/apt-command-guide/)![](https://itsfoss.com/content/images/wordpress/2017/07/apt-commands-example.png)


![](https://itsfoss.com/content/images/wordpress/2017/07/apt-commands-example.png)

The word update and upgrades are similar, and this is why it confuses a lot of new users. At times, I think the *apt update* command should be merged with the *apt upgrade* command.

I mean, the upgrade (of installed package versions) works in conjugation with the update (of local package metadata cache). Why have two separate commands for that? Combine them in a single upgrade command. This is what Fedora has done with the DNF command. That’s just my opinion.

I hope this article cleared some air around the usage of *apt-get update*, *apt-get upgrade* and *apt update* and *apt upgrade* commands.

Do let me know if you have any questions.