Download package using package manager

How to download the package using YUM or APT

Learn how to download packages from YUM or APT repository. The standalone package can be used to install on another server that has no YUM or APT configured.

Process to download package using YUM or APT

Many production environments don’t prefer to configure YUM or APT repositories on all servers. This is to avoid accidental installation of packages or up-gradating packages, which may cause issues on operations. Most of them use a centralized patch server to push updates to all servers.

If you want to install a single package on a server in such a setup, you need to have a standalone package file .rpm or .deb with you—directly downloading packages from the internet is not allowed in production areas. So you have to get packages from the server with registered YUM or APT repository configured.

The good news is you can download the package using YUM or APT! Later this package can be transferred to the intended server and can be installed. See below steps to download packages :

Download package on YUM configured server

Using downloadonly switch with yum command is a way to download packages on yum supported servers (Red Hat, CentOS). You need to fire yum install command and instruct it to download only without installing a package.

# yum install telnet --downloadonly
Loaded plugins: amazon-id, rhui-lb, search-disabled-repos
Resolving Dependencies
--> Running transaction check
---> Package telnet.x86_64 1:0.17-60.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================
 Package                      Arch                         Version                              Repository                                              Size
=============================================================================================================================================================
Installing:
 telnet                       x86_64                       1:0.17-60.el7                        rhui-REGION-rhel-server-releases                        63 k

Transaction Summary
=============================================================================================================================================================
Install  1 Package

Total download size: 63 k
Installed size: 113 k
Background downloading packages, then exiting:
telnet-0.17-60.el7.x86_64.rpm                                                                                                         |  63 kB  00:00:00
exiting because "Download Only" specified

In the above output, the install process exists since we specified download the only option (see the highlighted line).

This downloaded package (.rpm) will be saved under /var/cache/yum/<architecture>/<OS>/<repository>/packages directory. A repository name can be seen in the above install command output under package details. We downloaded packages on the RHEL7 server running on x86_64 architecture. See where our package (.rpm) got downloaded :

# pwd
/var/cache/yum/x86_64/7Server/rhui-REGION-rhel-server-releases/packages
# ll
total 68
-rw-r--r--. 1 root root 64872 Nov  6 11:09 telnet-0.17-60.el7.x86_64.rpm

Alternatively, you can install yum-utils and then use the yumdownloader program to download the RPM from a repo in your PWD.

# yum install yum-utils -y
# yumdownloader telnet
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
telnet-0.17-65.amzn2.x86_64.rpm                                                                                                                  |  64 kB  00:00:00
# ll
total 68
-rw-r--r-- 1 root root 65496 May  5  2020 telnet-0.17-65.amzn2.x86_64.rpm

Download package on APT configured server

On APT supported servers like Debian, ubuntu you need to use -d option in apt-get install command.

# apt-get install -d telnet
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  telnet
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/63.5 kB of archives.
After this operation, 182 kB of additional disk space will be used.
Download complete and in download only mode

This will download package in /var/cache/apt/archives.

# pwd
/var/cache/apt/archives

# ll
total 72
drwxr-xr-x 2 root root  4096 Mar  6 11:55 ./
drwx------ 4 root root  4096 Mar  6 12:02 ../
-rw-r--r-- 1 root root 63460 May  6  2015 telnet_0.17-40_amd64.deb
----output clipped ----

Check telnet package file .deb is downloaded in the current directory. If you want to download them in the current working directory, use download option instead of install. So no hassle of tracking down the package in a variable path like yum!

# pwd
/tmp/mypackages
# apt-get download  ssh
Get:1 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/main amd64 ssh all 1:7.2p2-4ubuntu2.1 [7,070 B]
Fetched 7,070 B in 0s (9,252 B/s)
# ll
total 16
drwxr-xr-x  2 root root 4096 May 17 10:17 ./
drwxr-xr-x 11 root root 4096 May 17 10:13 ../
-rw-r--r--  1 root root 7070 Aug 15  2016 ssh_1%3a7.2p2-4ubuntu2.1_all.deb

You can see the ssh package got downloaded within the same working directory. Now this package can be transferred to other servers (where repositories are not configured) for installation!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.