apt full-upgrade 与 apt-get dist-upgrade

apt full-upgrade 与 apt-get dist-upgrade

根据手册页:

  • apt有参数full-upgrade
  • apt-get有参数dist-upgrade

两者都是同一个命令吗?

顺便问一下: Ubuntu 16.04 中官方推荐的命令是什么?apt或者apt-get

答案1

是的,它们是相同的命令。apt 的这一部分cmdline/apt.cc证明这一点:

static std::vector<aptDispatchWithHelp> GetCommands()            /*{{{*/
{
   return {
      // [snip]
    
      // system wide stuff
      {"update", &DoUpdate, _("update list of available packages")},
      {"upgrade", &DoUpgrade, _("upgrade the system by installing/upgrading packages")},
      {"full-upgrade", &DoDistUpgrade, _("upgrade the system by removing/installing/upgrading packages")},
    
      // misc
      {"edit-sources", &EditSources, _("edit the source information file")},
      {"moo", &DoMoo, nullptr},
    
      // for compat with muscle memory
      {"dist-upgrade", &DoDistUpgrade, nullptr},
    
      // [snip]
   };
}

为了完整起见,cmdline/apt-get.cc

static std::vector<aptDispatchWithHelp> GetCommands()           /*{{{*/
{
   return {
      // [snip]
      {"dist-upgrade", &DoDistUpgrade, _("Distribution upgrade, see apt-get(8)")},
      {"full-upgrade", &DoDistUpgrade, nullptr},
      // [snip]
   };
}

对于和aptapt-get以及full-upgradedist-upgrade引用相同的DoDistUpgrade函数,因此执行相同的操作,只是apt这里的默认选项不同:

当软件包通过 apt(8) 成功安装后,相应的 .deb 软件包文件将从 /var/cache/apt/archives 缓存目录中删除

APT::Keep-Downloaded-Packages可以控制的这种行为apt-get

奖金调查

@Lii 提出了一个很好的观点,即DoDistUpgrade根据所使用的二进制文件(即argv[0])可能会采取不同的操作。代码比我预期的要简单得多,因为需要考虑多个层和全局变量,但让我们看一下。

ParseCommandLine功能用于两个二进制文件。该函数执行以下步骤,其中命令行可能会产生影响:

  1. InitLocale(Binary):所有情况的代码相同。

  2. pkgInitConfig(**Cnf):所有情况都使用extern Configuration *_config全局变量。

  3. BinarySpecificConfiguration(argv[0]):现在这很有趣。apt具有以下有意义的默认选项,它们不同于apt-get

    1. APT::Get::Upgrade-Allow-New = true。这是默认启用的--with-new-pkgs选项。这在手册中有记录,但这里的影响仅限于命令。apt-getaptupgrade
    2. APT::Keep-Downloaded-Packages = falseapt这是和之间的实际差异apt-get并在新闻文件

    [ 安装后自动删除 deb] 当软件包通过 apt(8) 成功安装后,相应的 .deb 软件包文件将从 /var/cache/apt/archives 缓存目录中删除。

    [...]

    请注意,apt-get 的行为没有改变。下载的 debs 在安装后将保留在缓存目录中。

  4. BinaryCommandSpecificConfiguration(argv[0], CmdCalled)两个二进制文件对所有这些命令执行相同的操作:"upgrade", "dist-upgrade", "full-upgrade"

  5. _config->MoveSubTree(conf.c_str(), nullptr)应用以所使用的二进制文件为前缀Binary::apt::aptBinary::apt::apt-get取决于所使用的二进制文件的选项。

省略了其他不相关的步骤。

DispatchCommandLine函数最终调用DoDistUpgrade处理程序。

在调用堆栈的后面,有一段有趣的DoCacheManipulationFromCommandLine()代码681

     bool const distUpgradeMode = strcmp(CmdL.FileList[0], "dist-upgrade") == 0 || strcmp(CmdL.FileList[0], "full-upgrade") == 0;

     bool resolver_fail = false;
     if (distUpgradeMode == true || UpgradeMode != APT::Upgrade::ALLOW_EVERYTHING)
        resolver_fail = APT::Upgrade::Upgrade(Cache, UpgradeMode, &Progress);

同样,使用任一命令的两个二进制文件都会执行相同的步骤。

也许我忽略了什么,但我就此停止调查。

答案2

apt full-upgrade执行与 相同的功能apt-get dist-upgrade

man apt

全面升级(apt-get(8))执行升级功能,但是如果需要升级整个系统,它将删除当前安装的软件包。

man apt-get

分布式升级除了执行升级功能外,还可以智能地处理软件包新版本依赖关系的变化;apt-get 有一个“智能”冲突解决系统,它会尝试升级最重要的软件包,而牺牲不太重要的软件包(如果有必要)。因此,dist-upgrade 命令可能会删除一些软件包。/etc/apt/sources.list 文件包含可从中检索所需软件包文件的位置列表。另请参阅 apt_preferences(5) 以了解覆盖单个软件包常规设置的机制。

答案3

首选使用 apt,但如果要编写脚本,则使用 apt-get。Apt-get 具有更稳定的输出(这意味着输出格式尽可能保持不变,以免破坏自动解析该输出的脚本)。Apt-get 还具有 apt 中没有的一些低级命令。

apt 和 apt-get 的手册页对 full-upgrade 和 dist-upgrade 的描述略有不同,但它们可能是相同的命令(apt 接受 dist-upgrade 作为 full-upgrade 的别名)。这很好地说明了 apt-gets 的稳定性。在 apt 中,名称已更改为更方便用户使用,而在 apt-get 中,名称保持不变,以免破坏与旧脚​​本的兼容性。

答案4

差异在于输出:

**易于

  • 全面升级

**

root@eesti-ThinkPad-T420:/home/eesti/apollo11# apt full-upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
  shim
Use 'sudo apt autoremove' to remove it.
0 uuendatud, 0 värskelt paigaldatud, 0 eemaldada ja 0 uuendamata.

**apt-get

  • 分布式升级

**

root@eesti-ThinkPad-T420:/home/eesti/apollo11# apt-get dist-upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following package was automatically installed and is no longer required:
  shim
Use 'sudo apt autoremove' to remove it.

*The following packages could receive security updates with UA Infra: ESM service enabled:
  libpam0g libdjvulibre-text bluez libwebp5 libdns-export162 libqpdf21 gstreamer1.0-alsa libisccfg140 intel-microcode libnss3-tools linux-headers-generic linux-libc-dev php7.0-cli vim-common libx11-xcb-dev libnss3-nssdb libcurl3 python-avahi libxml2-utils libgrilo-0.2-1 gstreamer1.0-plugins-base-apps libpam-modules openssl ruby2.3 bluez-cups imagemagick ntfs-3g git-man libsystemd0 linux-image-generic libgd3 libavahi-glib1 nginx-core libicu55 binutils libmagickwand-6.q16-2 squashfs-tools bind9-host php7.0-opcache linux-signed-image-generic libavahi-common-data dnsutils libavahi-common3 libpython3.5 python3.5 php7.0-common git openssh-sftp-server python3.5-minimal libisc160 udev gstreamer1.0-plugins-base libpam-runtime isc-dhcp-common python3.5-dev apache2-data libx11-6 linux-signed-generic nginx-common libudev1 libwebpdemux1 libavahi-ui-gtk3-0 libaspell15 libapr1 apport imagemagick-6.q16 libmagickcore-6.q16-2-extra php7.0-json libisc-export160 libudev-dev libruby2.3 libcaca0 php7.0-readline python3-apport avahi-daemon systemd-sysv libcurl4-openssl-dev libavahi-core7 libgcrypt20 liblwres141 vim-runtime liblz4-1 vim libpam-systemd libgstreamer-plugins-base1.0-0 distro-info-data libsndfile1 avahi-dnsconfd gstreamer1.0-x systemd libpython3.5-dev gir1.2-gst-plugins-base-1.0 libssl-dev libssl-doc libwebpmux1 mysql-common libpam-modules-bin openssh-server libx11-data aspell libopenexr22 openssh-client libmagickcore-6.q16-2 python-libxml2 libmysqlclient20 avahi-autoipd libdns162 libx11-dev qpdf libx11-doc bluez-obexd libdjvulibre21 apport-gtk libxml2 libnss3 apache2-bin ca-certificates vim-tiny imagemagick-common libisccc140 avahi-utils libpython3.5-stdlib libbind9-140 libbluetooth3 libexiv2-14 libavahi-compat-libdnssd1 apache2 libpython3.5-minimal libavahi-client3 apache2-utils curl isc-dhcp-client avahi-discover rpcbind linux-generic libapache2-mod-php7.0 python3-problem-report libcurl3-gnutls libx11-xcb1 libssl1.0.0 tzdata docker.io nginx
Learn more about UA Infra: ESM service for Ubuntu 16.04 at https://ubuntu.com/16-04

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

0 uuendatud, 0 värskelt paigaldatud, 0 eemaldada ja 0 uuendamata.
root@eesti-ThinkPad-T420:/home/eesti/apollo11# 

所以如你所见,它并不是真正“相同”的

相关内容