您当前的位置:首页 > 计算机 > 系统应用 > Linux

如何从 apt upgrade 中排除指定包

时间:12-14来源:作者:点击数:
城东书院 www.cdsy.xyz

在 archlinux 下可以直接通过 pacman -Syu --ingore 来跳过指定包进行升级,然而 ubuntu 下的 apt 居然不提供类似的排除选项,这很让我感到吃惊,不过网上 apt 的内容倒是蛮多,经过简单的搜索,很容易找到解决方法。

  1. 先用 apt-mark hold 来保留要排除的软件包
    sudo apt-mark hold emacs-snapshot
    
    emacs-snapshot set on hold.
    
    
  2. 执行升级操作
    sudo apt upgrade -y
    
  3. 用 apt-mark unhold 来取消包的保留
    sudo apt-mark unhold emacs-snapshot
    
    Canceled hold on emacs-snapshot.
    
    

如果没有 apt-mark 命令,则还可以使用 dpkg --set-selections 来保留软件包,关于它的 manual 如下:

--set-selections
            Set package selections using file read from stdin. This file should be in the format  “package  state”,
            where  state  is one of install, hold, deinstall or purge. Blank lines and comment lines beginning with
            ‘#’ are also permitted.

            The available file needs to be up-to-date for this command to be  useful,  otherwise  unknown  packages
            will be ignored with a warning. See the --update-avail and --merge-avail commands for more information.

所以步骤可以修改为

  1. 保留要排除的软件包
    echo "emacs-snapshot hold" |sudo dpkg --set-selections
    
  2. 执行升级操作
    sudo apt upgrade -y
    
  3. 取消包的保留
    echo "emacs-snapshot install" |sudo dpkg --set-selections
城东书院 www.cdsy.xyz
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门
本栏推荐