使用dnf shell安装本地rpm包的遇到的问题
- 序
- dnf local install
- dnf shell
- 注意
- 总结
- ref
序
最近项目中使用dnf安装本地安装包遇到了2个问题,调试了蛮久,记录下来,也供大家参考。
dnf是yum的升级版,在redhat8之后yum逐渐升级为dnf,基本的功能与yum差别不是很大
本人使用dnf 4.4.2来实验,可能版本升级后有所不同。
dnf local install
dnf不仅可以安装仓库提供的rpm包,也可以安装本地打包或者下载好的rpm包。如果本地缺少依赖包,dnf也依然会去默认的仓库去拉取。
为了测试方便,我们先从仓库下载几个包下来:
# --downloadonly:仅下载,不安装
$ dnf install gcc --downloadonly --destdir ./gcc/
Last metadata expiration check: 1 day, 2:29:19 ago on Thu 19 May 2022 08:25:23 PM EDT.
Dependencies resolved.
===========================================================================================================Package Architecture Version Repository Size
===========================================================================================================
Installing:gcc x86_64 8.4.1-1.el8 el8 23 M
Installing dependencies:annobin x86_64 9.50-1.el8 el8 106 kbinutils x86_64 2.30-93.el8 el8 5.8 Mcpp x86_64 8.4.1-1.el8 el8 10 Mglibc-devel x86_64 2.28-151.el8 el8 1.0 Mglibc-headers x86_64 2.28-151.el8 el8 477 kisl x86_64 0.16.1-6.el8 el8 835 kkernel-headers x86_64 4.18.0-147.5.1.el8_24 el8 2.7 Mlibmpc x86_64 1.1.0-9.1.el8 el8 60 klibpkgconf x86_64 1.4.2-1.el8 el8 34 klibxcrypt-devel x86_64 4.1.1-4.el8 el8 24 kpkgconf x86_64 1.4.2-1.el8 el8 37 kpkgconf-m4 noarch 1.4.2-1.el8 el8 16 kpkgconf-pkg-config x86_64 1.4.2-1.el8 el8 14 kTransaction Summary
============================================================================================================
Install 14 PackagesTotal download size: 45 M
Installed size: 122 M
DNF will only download packages for the transaction.
Is this ok [y/N]: y
Downloading Packages:
(1/14): annobin-9.50-1.el8.x86_64.rpm 270 kB/s | 106 kB 00:00
(2/14): binutils-2.30-93.el8.x86_64.rpm 755 kB/s | 5.8 MB 00:07
(3/14): glibc-devel-2.28-151.el8.x86_64.rpm 486 kB/s | 1.0 MB 00:02
(4/14): glibc-headers-2.28-151.el8.x86_64.rpm 407 kB/s | 477 kB 00:01
(5/14): isl-0.16.1-6.el8.x86_64.rpm 355 kB/s | 835 kB 00:02
(6/14): kernel-headers-4.18.0-147.5.1.el8_24.x86_64.rpm 290 kB/s | 2.7 MB 00:09
(7/14): libmpc-1.1.0-9.1.el8.x86_64.rpm 230 kB/s | 60 kB 00:00
(8/14): libpkgconf-1.4.2-1.el8.x86_64.rpm 58 kB/s | 34 kB 00:00
(9/14): libxcrypt-devel-4.1.1-4.el8.x86_64.rpm 215 kB/s | 24 kB 00:00
(10/14): pkgconf-1.4.2-1.el8.x86_64.rpm 225 kB/s | 37 kB 00:00
(11/14): pkgconf-m4-1.4.2-1.el8.noarch.rpm 162 kB/s | 16 kB 00:00
(12/14): pkgconf-pkg-config-1.4.2-1.el8.x86_64.rpm 158 kB/s | 14 kB 00:00
(13/14): cpp-8.4.1-1.el8.x86_64.rpm 365 kB/s | 10 MB 00:29
(14/14): gcc-8.4.1-1.el8.x86_64.rpm 587 kB/s | 23 MB 00:40
------------------------------------------------------------------------------------------------------------
Total 1.1 MB/s | 45 MB 00:41
Complete!$ ls gcc/
annobin-9.50-1.el8.x86_64.rpm kernel-headers-4.18.0-147.5.1.el8_24.x86_64.rpm
binutils-2.30-93.el8.x86_64.rpm libmpc-1.1.0-9.1.el8.x86_64.rpm
cpp-8.4.1-1.el8.x86_64.rpm libpkgconf-1.4.2-1.el8.x86_64.rpm
gcc-8.4.1-1.el8.x86_64.rpm libxcrypt-devel-4.1.1-4.el8.x86_64.rpm
glibc-devel-2.28-151.el8.x86_64.rpm pkgconf-1.4.2-1.el8.x86_64.rpm
glibc-headers-2.28-151.el8.x86_64.rpm pkgconf-m4-1.4.2-1.el8.noarch.rpm
isl-0.16.1-6.el8.x86_64.rpm pkgconf-pkg-config-1.4.2-1.el8.x86_64.rpm
我们准备了关于gcc的这些包。然后安装就可以使用dnf local install(install):
$ dnf install ./gcc/*.rpm
Last metadata expiration check: 1 day, 2:35:00 ago on Thu 19 May 2022 08:25:23 PM EDT.
Dependencies resolved.
===========================================================================================================Package Architecture Version Repository Size
===========================================================================================================
Installing:annobin x86_64 9.50-1.el8 @commandline 106 kbinutils x86_64 2.30-93.el8 @commandline 5.8 Mcpp x86_64 8.4.1-1.el8 @commandline 10 Mgcc x86_64 8.4.1-1.el8 @commandline 23 Mglibc-devel x86_64 2.28-151.el8 @commandline 1.0 Mglibc-headers x86_64 2.28-151.el8 @commandline 477 kisl x86_64 0.16.1-6.el8 @commandline 835 kkernel-headers x86_64 4.18.0-147.5.1.el8_24 @commandline 2.7 Mlibmpc x86_64 1.1.0-9.1.el8 @commandline 60 klibpkgconf x86_64 1.4.2-1.el8 @commandline 34 klibxcrypt-devel x86_64 4.1.1-4.el8 @commandline 24 kpkgconf x86_64 1.4.2-1.el8 @commandline 37 kpkgconf-m4 noarch 1.4.2-1.el8 @commandline 16 kpkgconf-pkg-config x86_64 1.4.2-1.el8 @commandline 14 kTransaction Summary
============================================================================================================
Install 14 Packages
# ...(略)
然后就可以安装了。
dnf shell
dnf/yum提供了shell的功能,即在一个shell,可以同时执行各种操作,但是是在一个事务中完成,我们来看下例子:
$ dnf shell
Last metadata expiration check: 1 day, 2:53:04 ago on Thu 19 May 2022 08:25:23 PM EDT.
> install gcc
> install libmpc
> install nginx
> remove wget
> run
============================================================================================================Package Architecture Version Repository Size
============================================================================================================
Installing:gcc x86_64 8.4.1-1.el8 el8 23 Mlibmpc x86_64 1.1.0-9.1.el8 el8 60 knginx x86_64 1:1.14.1-9.el8 el8 566 k
Installing dependencies:annobin x86_64 9.50-1.el8 el8 106 kbinutils x86_64 2.30-93.el8 el8 5.8 Mcpp x86_64 8.4.1-1.el8 el8 10 Mgd x86_64 2.2.5-7.el8 el8 143 kglibc-devel x86_64 2.28-151.el8 el8 1.0 Mglibc-headers x86_64 2.28-151.el8 el8 477 kisl x86_64 0.16.1-6.el8 el8 835 kjbigkit-libs x86_64 2.1-14.el8 el8 54 kkernel-headers x86_64 4.18.0-147.5.1.el8_24 el8 2.7 MlibXpm x86_64 3.5.12-8.el8 el8 57 klibjpeg-turbo x86_64 1.5.3-10.el8 el8 154 klibpkgconf x86_64 1.4.2-1.el8 el8 34 klibtiff x86_64 4.0.9-18.el8 el8 187 klibwebp x86_64 1.0.0-1.el8 el8 271 klibxcrypt-devel x86_64 4.1.1-4.el8 el8 24 klibxslt x86_64 1.1.32-6.el8 el8 249 knginx-all-modules noarch 1:1.14.1-9.el8 el8 22 knginx-filesystem noarch 1:1.14.1-9.el8 el8 23 knginx-mod-http-image-filter x86_64 1:1.14.1-9.el8 el8 34 knginx-mod-http-perl x86_64 1:1.14.1-9.el8 el8 44 knginx-mod-http-xslt-filter x86_64 1:1.14.1-9.el8 el8 32 knginx-mod-mail x86_64 1:1.14.1-9.el8 el8 63 knginx-mod-stream x86_64 1:1.14.1-9.el8 el8 84 kpkgconf x86_64 1.4.2-1.el8 el8 37 kpkgconf-m4 noarch 1.4.2-1.el8 el8 16 kpkgconf-pkg-config x86_64 1.4.2-1.el8 el8 14 k
Removing:wget x86_64 1.19.5-10.el8 @el8 2.8 M
Removing unused dependencies:libmetalink x86_64 0.1.3-7.el8 @el8 70 kTransaction Summary
===========================================================================================================
Install 29 Packages
Remove 2 PackagesTotal download size: 47 M
Is this ok [y/N]:
我们看到在一个事务中,同时执行了install gcc,install libmpc,install nginx,remove wget命令,然后通过run来触发执行事务,我们便可以在这个事务同时做多个安装或者删除的操作,对于比较大型项目中,dnf shell还是比较实用的。
注意
上边说了dnf的local install及shell, 当前local install也可以在dnf shell中执行。不过也注意几个事情,我们先来看第一个要注意的点,看下例子,我们想要安装刚刚本地下来的一些gcc rpm包
$ dnf shell
Last metadata expiration check: 1 day, 3:03:23 ago on Thu 19 May 2022 08:25:23 PM EDT.
> install /root/gcc/annobin-9.50-1.el8.x86_64.rpm
> install /root/gcc/binutils-2.30-93.el8.x86_64.rpm
Error: Cannot add local packages, because transaction job already exists
哈,当我们添加第二个的时候,就报了一个不能添加local package了错误,我们执行run试试:
> run
============================================================================================================Package Architecture Version Repository Size
===========================================================================================================
Installing:annobin x86_64 9.50-1.el8 @commandline 106 k
Installing dependencies:binutils x86_64 2.30-93.el8 el8 5.8 Mcpp x86_64 8.4.1-1.el8 el8 10 Mgcc x86_64 8.4.1-1.el8 el8 23 Mglibc-devel x86_64 2.28-151.el8 el8 1.0 Mglibc-headers x86_64 2.28-151.el8 el8 477 kisl x86_64 0.16.1-6.el8 el8 835 kkernel-headers x86_64 4.18.0-147.5.1.el8_24 el8 2.7 Mlibmpc x86_64 1.1.0-9.1.el8 el8 60 klibpkgconf x86_64 1.4.2-1.el8 el8 34 klibxcrypt-devel x86_64 4.1.1-4.el8 el8 24 kpkgconf x86_64 1.4.2-1.el8 el8 37 kpkgconf-m4 noarch 1.4.2-1.el8 el8 16 kpkgconf-pkg-config x86_64 1.4.2-1.el8 el8 14 k
可以看到Installing中只会包含第一个annobin(仓库那一栏显示@commandline),我们添加进来的binutils不会安装,只是会从repo拉取annobin的依赖包(Installing dependencies)时刚好拉取到。
那我们放置在一行(空格分开)会出现什么情况呢:
dnf shell
Last metadata expiration check: 1 day, 3:10:09 ago on Thu 19 May 2022 08:25:23 PM EDT.
> install /root/gcc/annobin-9.50-1.el8.x86_64.rpm /root/gcc/binutils-2.30-93.el8.x86_64.rpm
> run
============================================================================================================Package Architecture Version Repository Size
============================================================================================================
Installing:annobin x86_64 9.50-1.el8 @commandline 106 kbinutils x86_64 2.30-93.el8 @commandline 5.8 M
Installing dependencies:cpp x86_64 8.4.1-1.el8 el8 10 Mgcc x86_64 8.4.1-1.el8 el8 23 Mglibc-devel x86_64 2.28-151.el8 el8 1.0 Mglibc-headers x86_64 2.28-151.el8 el8 477 kisl x86_64 0.16.1-6.el8 el8 835 kkernel-headers x86_64 4.18.0-147.5.1.el8_24 el8 2.7 Mlibmpc x86_64 1.1.0-9.1.el8 el8 60 klibpkgconf x86_64 1.4.2-1.el8 el8 34 klibxcrypt-devel x86_64 4.1.1-4.el8 el8 24 kpkgconf x86_64 1.4.2-1.el8 el8 37 kpkgconf-m4 noarch 1.4.2-1.el8 el8 16 kpkgconf-pkg-config x86_64 1.4.2-1.el8 el8 14 kTransaction Summary
============================================================================================================
Install 14 Packages
可以看到会安装annobin及binutils两个包,也就是可以执行成功。
那么我们也就可以得到结论,使用dnf shell 安装本地包时,需要将要安装的包都写在同一行,否则只会安装第一行包。
我们也可以在dnf文档这里找到相关的记录,和我们得出的结论也是一致的:
Note that all local packages must be used in the first shell transaction subcommand (e.g. install /tmp/nodejs-1-1.x86_64.rpm /tmp/acpi-1-1.noarch.rpm) otherwise an error will occur.
总结
这里列出来本人使用dnf shell遇到的一个问题,以此共勉。主要是在dnf shell中不能多行install本地rpm包,否则只有第一行奏效。
ref
https://dnf.readthedocs.io/en/latest/command_ref.html