解决 yum install 命令 --downloadonly 参数出错的方法

使用 yum 命令可以安装或者更新一个 RPM 包,并且自动解决依赖关系。但有时需要将一个 RPM 包下载到本地计算机,可以使用–downloadonly 参数。

yum 命令可以用来下载一个RPM包,标准的 yum 命令提供了–downloadonly 参数达到这个目的。使用 --downloaddir 参数指定 RPM 存放的目录。

代码如下:

$ yum install -y 包名 --downloadonly --downloaddir=目录

如果下载的包包含了任何没有满足的依赖关系,yum 将会把所有的依赖关系包下载,但是不会被安装。

在 CentOS6 或更早期的版本中,需要安装一个单独的 yum 插件(名称为 yum-plugin-downloadonly)才能使用
–downloadonly 选项,否则会报如下错误:

[root@test soft]# yum install -y readline --downloadonly --downloaddir=/soft/readline/
Usage: yum [options] COMMAND

List of Commands:

check          Check for problems in the rpmdb
check-update   Check for available package updates
clean          Remove cached data
deplist        List a package's dependencies
distribution-synchronization Synchronize installed packages to the latest available versions
downgrade      downgrade a package
erase          Remove a package or packages from your system
groupinfo      Display details about a package group
groupinstall   Install the packages in a group on your system
grouplist      List available package groups
groupremove    Remove the packages in a group from your system
help           Display a helpful usage message
history        Display, or use, the transaction history
info           Display details about a package or group of packages
install        Install a package or packages on your system
list           List a package or groups of packages
load-transaction load a saved transaction from filename
makecache      Generate the metadata cache
provides       Find what package provides the given value
reinstall      reinstall a package
repolist       Display the configured software repositories
resolvedep     Determine which package provides the given dependency
search         Search package details for the given string
shell          Run an interactive yum shell
update         Update a package or packages on your system
upgrade        Update packages taking obsoletes into account
version        Display a version for the machine and/or available repos.

############### 出错信息如下:###################################
Command line error: no such option: --downloadonly

使用以下命令安装插件:

[root@test soft]# yum install yum-plugin-downloadonly
base                                       | 3.7 kB     00:00     
extras                                     | 3.4 kB     00:00     
updates                                    | 3.4 kB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package yum.noarch 0:3.2.29-40.el6.centos will be updated
---> Package yum.noarch 0:3.2.29-81.el6.centos.0.1 will be an update
--> Processing Dependency: python-urlgrabber >= 3.9.1-10 for package: yum-3.2.29-81.el6.centos.0.1.noarch
--> Running transaction check
---> Package python-urlgrabber.noarch 0:3.9.1-9.el6 will be updated
---> Package python-urlgrabber.noarch 0:3.9.1-11.el6 will be an update
--> Finished Dependency Resolution

Dependencies Resolved
============================================================================
 Package               Arch         Version          Repository          Size
=============================================================================
Updating:
 yum              noarch         3.2.29-81.el6.centos.0.1       updates    1.0 M
Updating for dependencies:
 python-urlgrabber          noarch         3.9.1-11.el6         base       86 k

Transaction Summary
===============================================================================
Upgrade       2 Package(s)

Total download size: 1.1 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): python-urlgrabber-3.9.1-11.el6.noarch.rpm        |  86 kB     00:00     
(2/2): yum-3.2.29-81.el6.centos.0.1.noarch.rpm          | 1.0 MB     00:00     
-------------------------------------------------------------------------------
Total                                                                                                                                       2.0 MB/s | 1.1 MB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating   : python-urlgrabber-3.9.1-11.el6.noarch           1/4 
  Updating   : yum-3.2.29-81.el6.centos.0.1.noarch             2/4 
  Cleanup    : yum-3.2.29-40.el6.centos.noarch                 3/4 
  Cleanup    : python-urlgrabber-3.9.1-9.el6.noarch            4/4 
  Verifying  : yum-3.2.29-81.el6.centos.0.1.noarch             1/4 
  Verifying  : python-urlgrabber-3.9.1-11.el6.noarch           2/4 
  Verifying  : yum-3.2.29-40.el6.centos.noarch                 3/4 
  Verifying  : python-urlgrabber-3.9.1-9.el6.noarch            4/4 

Updated:
  yum.noarch 0:3.2.29-81.el6.centos.0.1                               

Dependency Updated:
  python-urlgrabber.noarch 0:3.9.1-11.el6                             

Complete!

重新执行 yum 命令下载 RPM 包,代码如下:

[root@test soft]# yum install -y wget --downloadonly --downloaddir=/soft/wget
设置安装进程
解决依赖关系
--> 执行事务检查
---> Package wget.x86_64 0:1.12-10.el6 will be 安装
--> 完成依赖关系计算

依赖关系解决

===============================================================================
 软件包             架构              版本                 仓库           大小
===============================================================================
正在安装:
 wget            x86_64        1.12-10.el6                base          484 k

事务概要
==============================================================================
Install       1 Package(s)

总下载量:484 k
Installed size: 1.8 M
下载软件包:
wget-1.12-10.el6.x86_64.rpm                                         | 484 kB     00:00     
exiting because --downloadonly specified
[root@test soft]# ls /soft/wget
wget-1.12-10.el6.x86_64.rpm
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐