2023年11月26日发(作者:)

ubuntu禁⽤软件包更新

Linux 操作系统进⾏系统更新在现在是个很普遍的事情。你可能会时常登录系统后,系统会提⽰你有可⽤的软件包可以进⾏更新;⼜或者修改了仓

库源后,需要及时更新软件源。

本来基于新功能或安全漏洞的更新是能让使⽤者安⼼的,不过对于⼀些服务器来讲,选择⼀个稳定可靠的软件版本是⾄关重要的。但是在更新软件

的时候,通常部署的应⽤软件也会随之进⾏更新,⽽这,肯定不会是我们所希望看到的。

例如,我在服务器上安装了 等⼀些应⽤软件,其中 的软件包近似1G,更新的时候不仅耗时,遇到⽹络波动更

gitlab-cenpmnginxgitlab-ce

可能导致更新失败;况且还有更新新版本后软件是否兼容也是⼀个疑问。

为了软件的稳定和可靠,只能选择在更新软件的时候忽略制定软件的更新了。

ubuntu 系统中常⽤的禁⽤软件包更新的⽅式有多种,其中最通常的两种⽤法是通过 实现禁⽤软件包更新。

dpkgapt-mark

apt-mark

apt-mark

是 ubuntu 操作系统中⽤来管理软件包更新的指令。主要通过对⾃动/⼿动安装的软件包进⾏标记来实现更新时的差异化处理。⼀个被

标记的软件包,使⽤ 命令升级软件包的时候会被识别到并且跳过该软件包的更新。

apt upgrade

主要参数如下

root@ubuntu:~# apt-mark -h

apt 2.0.6 (amd64)

Usage: apt-mark [options] {auto|manual} pkg1 [pkg2 ...]

apt-mark is a simple command line interface for marking packages

as manually or automatically installed. It can also be used to

manipulate the dpkg(1) selection states of packages, and to list

all packages with or without a certain marking.

Most used commands:

auto - Mark the given packages as automatically installed

manual - Mark the given packages as manually installed

minimize-manual - Mark all dependencies of meta packages as automatically installed.

hold - Mark a package as held back

unhold - Unset a package set as held back

showauto - Print the list of automatically installed packages

showmanual - Print the list of manually installed packages

root@ubuntu:~# apt-mark showmanual | grep ^g

gcc

gitlab-ce

gnupg

gnupg2

grep

gzip

这⾥可以看到 属于需要⼿动进⾏安装的软件包。因此,每次在执⾏ 的时候默认会进⾏ 的更新

gitlab-ceapt-get upgradegitlab-ce

将 gitlab-ce 设置为模式

hold

root@ubuntu:~# apt-mark hold gitlab-ce

root@ubuntu:~# apt-get upgrade

Reading Done

Building dependency tree

Reading Done

Done

The following packages have been kept back:

gitlab-ce linux-image-generic nginx

The following packages will be upgraded:

libpolkit-agent-1-0 libpolkit-gobject-1-0 libruby2.7 linux-crashdump policykit-1 ruby2.7 vim vim-common vim-runtime vim-tiny xxd

11 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.