Is there a way to download all dependencies with yumdownloader, even if they are already installed?
I'm trying to create a local repo and only want to include the packages we need.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIs there a way to download all dependencies with yumdownloader, even if they are already installed?
I'm trying to create a local repo and only want to include the packages we need.
You can use repotrack
instead like this:
repotrack -a x86_64 -p /repos/Packages [packages]
Unfortunately there is a bug with the -a
flag (arch). It will download i686 and x86_64.
Here's how to fix it:
if opts.arch:
#archlist = []
#archlist.extend(rpmUtils.arch.getArchList(opts.arch))
archlist = opts.arch.split(',') # Change to this
else:
archlist = rpmUtils.arch.getArchList()
You can use repoquery
to get a list of group packages:
repoquery --qf=%{name} -g --list --grouppkgs=all [groups]
Which you can feed into repotrack:
repoquery --qf=%{name} -g --list --grouppkgs=all [groups] | xargs repotrack -a x86_64 -p /repos/Packages
--requires
--resolve
option doesn't work recursively for deps.
– Luke
Oct 13 '12 at 1:32
--recursive
option to the repoquery command to get it work recursively.
– ZaSter
May 7 '13 at 22:40
yum-utils
project. The reason why it downloads more packages than expected is because the function rpmUtils.arch.getArchList()
returns all compatible architectures for the given one. It includes for example the noarch
architecture which may be needed by x86_64
packages. You can check the source: yum.baseurl.org/gitweb?p=yum.git;a=blob;f=rpmUtils/…
– Samuel Phan
Aug 16 '16 at 16:13
For everyone's information, yumdownloader
does not do the job. For anyone with some experience in package management with `yum, it is natural to expect that the following command-line would recursively download a package RPM and all its dependencies:
yumdownloader --resolve <package>
But it does not. May be it prints first-level dependencies or those that are not already installed. I am not sure.
Here is one method that works on CentOS 6.5. Follow the steps to install the downloadonly plugin for yum
as given by Red Hat. Basically, on CentOS 6.x, do:
$ sudo yum install yum-plugin-downloadonly.noarch
Then make use of the plugin in combination with the --installroot
switch of yum
. This prevents yum
from resolving and then skipping dependencies that are already installed on the system.
sudo yum install \
--installroot=</path/to/tmp_dir> \
--downloadonly --downloaddir <rpm_dir> <package>
You would downloaded RPMs of the package, <package>
and all its dependencies in the directory, <rpm_dir>
. Example, with Git:
$ mkdir root rpms
$ sudo yum install --installroot=/home/roy/root \
--downloadonly --downloaddir rpms/ git
sudo yum install yum-plugin-downloadonly.noarch
says No package yum-plugin-downloadonly.noarch available.
what to do?
– Howard Lee
Jun 27 '16 at 22:44
Cannot find a valid baseurl for repo: base/$releasever/x86_64
when I add the --installroot
flag.
– Mike S
Nov 18 '16 at 23:40
Also try
repoquery -R --resolve --recursive <name> | xargs -r yumdownloader
e.g.:
repoquery -R --resolve --recursive firefox | xargs -r yumdownloader
repotrack
kept finding packages that weren't available when I tried getting wine
. Thanks!
– Dan
Jul 21 '20 at 18:44
repoquery --required --resolve --recursive docker-ce | xargs -r yumdownloader
. As @Dan stated nothing else worked for me once I had Docker-CE already installed on the machine I was trying to get the dependancies from.
– jamescampbell
Mar 1 at 2:52
If you're from the future (Fedora 23+), where yum is getting replaced with dnf, you might find this bash script useful.
rpmDownloader:
#!/bin/sh
set -xev
rm -fr packages
#dnf download $1 --destdir packages
export PATH=.:$PATH
echo $PWD
DEPS=$(rpmResolver $1)
dnf download $DEPS --destdir packages
rm -fr ${1}-dependencies
mv packages ${1}-dependencies
rpmResolver:
#!/bin/sh
goal=$1
deps=$(rpm -q --qf '[%{REQUIRENAME}\n]' $goal | egrep -v '^(rpmlib|rtld|config|/)')
goals=
while true; do
subs=$(rpm -q --qf '%{NAME}\n' --whatprovides $deps | sort -u | tr '\n' ' ')
if [ ."$subs" = ."$goals" ]; then
echo -n "$goals "
exit 0
fi
goals=$(echo $goals $subs | tr ' ' '\n' | sort -u | tr '\n' ' ')
for sub in $subs; do
subdeps=$(rpm -q --qf '[%{REQUIRENAME}\n]' $sub | egrep -v '^(rpmlib|rtld|config|/)')
deps=$(echo $deps $subdeps | sort -u)
done
done
I found that in practice building a repo like this difficult to maintain. We built this repo because:
The issues we can across were:
In the end the better solution to our problem was to proxy the official repos and cache the packages we used. This works out well because:
We used Nginx and the built-in proxy support.
I realize the thread is old, but in case anyone stumbles across this, you can use yum to accomplish the desired behavior.
First instally the downloadonly plugin(instructions for RHEL): (RHEL5)
$ yum install yum-downloadonly
(RHEL6)
$ yum install yum-plugin-downloadonly
Next run the command as follows:
$ yum install --downloadonly --downloaddir=/some/arbitrary/path [package]
If you ignore the --downloaddir
yum will automatically download to /var/cache/yum
So unless you need to use yumdownloader specifically I think this would be the simplest way to accomplish the goal.
Building on Luke's answer and the comments...
As of this writing repotrack
will match all of the following architectures when x86_64
is specified: x86_64
, athlon
, i686
, i586
, i486
, i386
, and noarch
.
For my purposes I am only interested in x86_64
and noarch
packages, and I know that my distribution doesn't have any athlon
packages.
The following command gets a list of package URLs, filters out i?86
architectures, and prints out the names of the packages as they are downloaded:
repotrack --arch=x86_64 --urls gs1000-server \
| sed '/\.i[3-6]86\.rpm$/d' \
| xargs -I {} sh -c 'curl -s -O {}; echo {} | rev | cut -d '/' -f 1 | rev'
Note that repotrack
does not warn you if it can't find a package that satisfies a dependency in your enabled repos. It silently skips it.