Home 使用apt降级软件包
Post
Cancel

使用apt降级软件包

dpkg和rpm的软件包都有版本信息,依赖信息。安装一个包,需要将它依赖的软件包(如果有)先装好。 有时安装软件时,软件包安装失败,提示信息大致为依赖冲突。系统中存在更高版本的依赖兑现表包,需要降级处理。 可以根据提示的版本信息,进行降级处理。

1
2
3
4
5
# check 包的历史版本信息
apt-cache policy [package name]

# 安装特定的版本的包(可以降级)
apt install [包名]=[特定版本信息]

示例

(1) 需要安装 libglib2.0-dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ sudo apt install libglib2.0-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libglib2.0-dev : Depends: libglib2.0-0 (= 2.64.6-1~ubuntu20.04.3) but 2.64.6-1~ubuntu20.04.4 is to be installed
                  Depends: libglib2.0-bin (= 2.64.6-1~ubuntu20.04.3)
E: Unable to correct problems, you have held broken packages.

提示报错,该软件依赖的两个软件包有问题,它依赖低版本的,而系统中安装了高版本的,无法安装,所以对相关依赖软件包降级。 两个依赖包不满足条件 libglib2.0-0包要求使用2.64.6-1~ubuntu20.04.3版本的,而系统中的版本更高( 2.64.6-1~ubuntu20.04.4), 另一个libglib2.0-bin包也需要 2.64.6-1~ubuntu20.04.3 版本的。

(2)查看包的历史版本信息

使用命令 apt-cache policy [package name]查看历史版本信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ sudo apt-cache policy libglib2.0-0
libglib2.0-0:
  Installed: 2.64.6-1~ubuntu20.04.4
  Candidate: 2.64.6-1~ubuntu20.04.4
  Version table:
 *** 2.64.6-1~ubuntu20.04.4 100
        100 /var/lib/dpkg/status
     2.64.6-1~ubuntu20.04.3 500
        500 https://mirrors.ustc.edu.cn/ubuntu focal-security/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
     2.64.2-1~fakesync1 500
        500 https://mirrors.ustc.edu.cn/ubuntu focal/main amd64 Packages

$ sudo apt-cache policy libglib2.0-bin
libglib2.0-bin:
  Installed: 2.64.6-1~ubuntu20.04.4
  Candidate: 2.64.6-1~ubuntu20.04.4
  Version table:
 *** 2.64.6-1~ubuntu20.04.4 100
        100 /var/lib/dpkg/status
     2.64.6-1~ubuntu20.04.3 500
        500 https://mirrors.ustc.edu.cn/ubuntu focal-security/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages
     2.64.2-1~fakesync1 500
        500 https://mirrors.ustc.edu.cn/ubuntu focal/main amd64 Packages

需要的低版本的依赖包都存在

(3)安装低版本的包(降级)

使用命令 apt install [包名]=[特定版本信息],默认不加 =[版本信息]就是安装最新的。

1
2
3
$ sudo apt install libglib2.0-0=2.64.6-1~ubuntu20.04.3
$ sudo apt install libglib2.0-bin=2.64.6-1~ubuntu20.04.3
## 安装过程中 dpkg会提示警告,软件降级。

最后安装开头的软件 ,sudo apt install libglib2.0-dev,即可通过。

阻止包默认升级

默认情况下,apt工具会检索包的新版本信息,并提示更新。出于稳定需求,如果需要保持一个包固定版本,不更新,可以让 apt 屏蔽该软件包。

屏蔽软件包升级

1
2
3
4
5
6
7
# 屏蔽
sudo apt-mark hold [package_name]
# 取消屏蔽
sudo apt-mark unhold [package_name]

# 查看已屏蔽升级的软件包
sudo apt-mark showhold

example
保持依赖包libglib2.0-0为固定版本,不更新。

1
2
3
4
5
$ sudo apt-mark hold libglib2.0-0
libglib2.0-0 set on hold.

$ sudo apt-mark showhold
libglib2.0-0
This post is licensed under CC BY 4.0 by the author.