Today, we’ll take a look at how we can use package managers to download only rpm packages(offline) without installing them with all dependencies on Linux.
Yum and Dnf package managers are used in RedHat distributions namely RedHat, CentOS and Fedora mostly for installation, reinstallation, update, upgrade and removal of rpm packages.
Note: Kindly note that yum-utils package has been deprecated in Centos & RHEL 7
There are two ways of downloading packages without installing them
1) yum-downloadonly utility
2) using yumdownloader
3) using dnf-download
Installing yum-downloadonly tool (CentOS & RHEL 6.8)
Let's first install the downloadonly utility with the command below.
yum install yum-plugin-downloadonly
Downloading a package using yum-downloadonly
Now that we have downloaded the utility tool, let's see how we can download a web server package (httpd)
yum install –-downloadonly httpd
[root@li1080-41 ~]# yum install --downloadonly httpd Loaded plugins: fastestmirror Setting up Install Process Loading mirror speeds from cached hostfile * base: mirrors.linode.com * extras: mirrors.linode.com * updates: mirrors.linode.com Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.2.15-60.el6.centos.6 will be installed --> Processing Dependency: httpd-tools = 2.2.15-60.el6.centos.6 for package: htt pd-2.2.15-60.el6.centos.6.x86_64 --> Processing Dependency: apr-util-ldap for package: httpd-2.2.15-60.el6.centos .6.x86_64 --> Processing Dependency: /etc/mime.types for package: httpd-2.2.15-60.el6.cent os.6.x86_64 --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.2.15- 60.el6.centos.6.x86_64 --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.2.15-60.e l6.centos.6.x86_64
NOTE: By default, the package is downloaded to /var/cache/yum directory. To specify an alternative path append the --downloaddir=/path/ flag e.g
yum -y install --downloadonly --downloaddir=/opt samba
The above command stores the samba package in the /opt directory.
Installing yumdownloader (CentOS & RHEL 7)
Install the EPEL repo first. Note that yum-utils is deprecated in Centos & RHEL 7
yum install epel-release
Downloading a package using yumdownloader
To download a package, run the command as shown below. The example shows the download of an openssh server.
The package is downloaded to the current working directory. You can specify an alternative directory by appending -- destdir flag.
To download the package alongside the dependencies, append the --resolve flag.
Verifying the presence of dependencies
Downloading a package using dnf (Fedora 22 and later versions)
On Fedora 22 and later, yum is deprecated and in its place is the dnf package manager. To download a package using dnf, run the command as shown. The example below illustrates download of samba package.
dnf download package-name Downloading with dependencies
To download the dependencies, append the --resolve flag
dnf download samba --resolve
Verify existence or download of dependencies
Check the presence of downloaded dependencies using the ls command.
- 21 DNF Commands to Manage RPM Based Linux Distributions
- How to Query Packages Using Linux RPM Command
Generally, the best and easiest way of installing packages is by using the yum install package-name 0r dnf install package-name commands. If you prefer downloading a package first and installing it later, ensure you download the dependencies as well using the --resolve flag and install all of them simultaneously to avoid getting dependencies errors.