Debian/Ubuntu系统下 apt-get update 、apt-get upgrade 、apt-get dist-upgrade 命令之间的区别


摘要:apt-get update和 apt-get upgrade之间有什么区别? 应该先跑哪个?


update is used to resynchronize the packageindex files from their sources. The indexes of available packages are fetchedfrom the location(s) specified in /etc/apt/sources.list. For example, whenusing a Debian archive, this command retrieves and scans the Packages.gz files,so that information about new and updated packages is available. An updateshould always be performed before an upgrade or dist-upgrade. Please be awarethat the overall progress meter will be incorrect as the size of the packagefiles cannot be known in advance.


upgrade is used to install the newestversions of all packages currently installed on the system from the sources enumerated in /etc/apt/sources.list.Packages currently installed with new versions available are retrieved and upgraded; under no circumstancesare currently installed packages removed, or packages not already installed retrieved and installed. Newversions of currently installed packages that cannot be upgraded without changing the install statusof another package will be left at their current version. An update must be performed first so that apt-getknows that new versions of packages are available.


dist-upgrade in addition to performing the function of upgrade, alsointelligently handles changing dependencies with new versions of packages; apt-get has a"smart" conflict resolution system, and it will attempt to upgrade the most important packages at the expense of lessimportant ones if necessary. The /etc/apt/sources.list file contains a list of locations from which toretrieve desired package files. See also apt_preferences(5) for a mechanism for overriding the generalsettings for individual packages.

上面内容均是从 apt-get 的 man文档里面截取下来的,从英文内容我们可以知道:

update:当执行 apt-get update 时,update 重点更新的是来自软件源的软件包的索引记录(即index files);更新可用软件包及其版本的列表,但不会安装或升级任何软件包。。

upgrade:当执行 apt-get upgrade 时,upgrade 是根据 update 更新的索引记录来下载并更新软件包;实际上安装了你的新版本的软件包。更新列表后,程序包管理器将了解您已安装的软件的可用更新。这就是你第一次要先执行 update 的原因。

dist-upgrade:当执行 apt-get dist-upgrade 时,除了拥有 upgrade 的全部功能外,dist-upgrade 会比 upgrade 更智能地处理需要更新的软件包的依赖关系

从上述可以看出,在执行 apt-get upgradeapt-get dist-upgrade 之前应该先执行 apt-get update


允许命令apt代替 apt-get 和 apt-cache 进行某些操作。

apt-get upgrade 不会改变安装的内容(仅限版本列表更新),

apt-get dist-upgrade 将根据需要安装或删除软件包以完成升级;apt upgrade 将自动安装但不会删除包。


apt-get 是在基于 Debain 的机器(如Ubuntu)中进行包/应用程序管理的命令。


sudo apt-get update # 获取最新资源包


sudo apt-get upgrade # 更新本机已安装的软件包


sudo apt-get dist-upgrade # 本机系统软件更新

dist-upgrade命令也算更新所有软件包,但是当 upgrade 更新时,如果依赖关系无法解决时可能会报错或者停止,但是 dist-upgrade 命令可以自动解决依赖关系

但是 dist-update 有一定的危险性,因为可能会更新很大您不希望更新的软件,导致原理的一些需要依赖旧包的软件无法运行。

所有,使用 apt-get dist-upgrade 时,请慎重使用,一般是 apt-get update && apt-get upgrade 可以保证系统的完整性。

---------------------------------- THE END ----------------------------------