Linux Package Management - Yum local repo

Setting Up a Local Yum Repository

YUM (YellowDog Updater Modified) is a package manager used for managing the installation, updating, and removing the software packages in a RedHat-based Linux system. To know more about yum commands and usage refer here

While setting up your yum repo files you can face a scenario where you dont have internet access on your servers, in which case using public repositories will not be possible. In such cases you can use the ISO image file and setup your local yum repositories. Local Yum Repositories can be setup in varous ways depending upon the level of access and need.

  1. Using ISO image available as mounted partition on your linux instance
  2. Using ISO image copied to your linux instance

Further the local repos can be mounted on an FTP to allow it to be used across your local network

Using ISO image available as mounted partition

If your instance is a virtual machine and you have access to the hypervisor console (Oracle Virtual Box, VMware or any other) then you can simply mount your ISO image and directly create a local repo.

You will need the ISO image for your OS present on the base machin on which hypervisor is running

Step 1 : Login to you system and run the lsblk command to check the partitions

lsblk output

Step 2 : Mount the ISO image from your hypervisor settings

mount iso image to your vm

Step 3: Check again to ensure the ISO image is mounted

[centos@client2 ~]$ sudo lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda           8:0    0 47.5G  0 disk
├─sda1        8:1    0    1G  0 part /boot
└─sda2        8:2    0 46.5G  0 part
  ├─cs-root 253:0    0 44.4G  0 lvm  /
  └─cs-swap 253:1    0  2.1G  0 lvm  [SWAP]
sr0          11:0    1  8.2G  0 rom  /run/media/root/CentOS-Stream-9-BaseOS-x86_64

Step 4 : Create a directory to act as the local repo

[centos@client2 ~]$ sudo mkdir /var/localrepo

Step 5 : Create a softlink to the iso image

[centos@client2 ~]$ sudo ln -s /run/media/root/CentOS-Stream-9-BaseOS-x86_64 /var/localrepo/

Step 6 : Install create repo rpm, you can find the rpms in the localrepo directory

[root@client2 ~]# cd /var/localrepo/CentOS-Stream-9-BaseOS-x86_64/AppStream/Packages/
[root@client2 Packages]# ls createrepo_c-*
createrepo_c-0.17.7-4.el9.x86_64.rpm createrepo_c-libs-0.17.7-4.el9.i686.rpm createrepo_c-libs-0.17.7-4.el9.x86_64.rpm
[root@client2 Packages]# rpm -ivh createrepo_c-0.17.7-4.el9.x86_64.rpm createrepo_c-libs-0.17.7-4.el9.x86_64.rpm
Verifying… ################################# [100%]
Preparing… ################################# [100%]
Updating / installing…
1:createrepo_c-libs-0.17.7-4.el9 ################################# [ 50%]
2:createrepo_c-0.17.7-4.el9 ################################# [100%]
[root@client2 Packages]#

Step 7 : Create Repo using createrepo command. (Createrepo creates additional directory repodata in the localrepo directory, with some informational files that are used by yum for fetching data from a reposiotry.)

 createrepo -v /var/localrepo

Step 8 : Create a yum repo file in /etc/yum.repos.d directory

[centos@midas ~]$ sudo vim /etc/yum.repos.d/centos9-local.repo

[localrepo]
name=Centos9 Localrepo
metadata_expire=-1
gpgcheck=0
enabled=1
baseurl=file:///var/localrepo/

Step 9 : Clean the yum cache and list the available repositories to check the configuration

[centos@midas ~]$ yum clean all
0 files removed
[root@client2 ~]# yum repolist
repo id                                           repo name
Localrepo                                         Centos9 Localrepo

Step 10 : Check by installing any package (say firefox if it is not already installed)

[root@client2 ~]# yum -y install firefox
Centos9 Localrepo                                                                          50 MB/s | 7.5 MB     00:00
Last metadata expiration check: 0:00:07 ago on Sun 16 Apr 2023 11:02:51 AM IST.
Dependencies resolved.
==========================================================================================================================
 Package                          Architecture           Version                          Repository                 Size
==========================================================================================================================
Installing:
 firefox                          x86_64                 91.11.0-2.el9                    Localrepo                 103 M
Installing dependencies:
 centos-indexhtml                 noarch                 9.0-0.el9                        Localrepo                 252 k

Transaction Summary
==========================================================================================================================
Install  2 Packages

By using ISO image copied to your linux instance

Step 1 : Copy your ISO image for your linux version to your linux instance

Step 2: Create a directory say in /var to act as your local repo

[centos@midas ~]$ sudo mkdir /var/localrepo

Step 3 : Loop mount iso image to the localrepo directory (This allows the mounting of a file as a physical media such as a hard disk, DVD, thus allowing you to mount the iso image without actually having to burn the DVD)

[centos@midas ~]$ sudo mount -o loop /home/centos/ISO/CentOS-Stream-9-latest-x86_64-dvd1.iso /var/localrepo/
mount: /var/localrepo: WARNING: source write-protected, mounted read-only.

[centos@midas ~]$ ls /var/localrepo/
AppStream  EFI   extra_files.json  isolinux  media.repo
BaseOS     EULA  images            LICENSE   TRANS.TBL

Step 4 : Create a repo file in /etc/yum.repos.d directory

[centos@midas ~]$ sudo vim /etc/yum.repos.d/centos9-local.repo

[Local-BaseOS]
name=Centos 9 BaseOS
metadata_expire=-1
gpgcheck=0
enabled=1
baseurl=file:///var/localrepo/BaseOS/

[Local-AppStream]
name=Centos 9 AppStream
metadata_expire=-1
gpgcheck=0
enabled=1
baseurl=file:///var/localrepo/AppStream/

Step 5 : Clean the yum cache and list the available repositories to check the configuration

[centos@midas ~]$ yum clean all
0 files removed

[centos@midas ~]$ yum repolist
repo id                                     repo name
Local-AppStream                             Centos 9  AppStream
Local-BaseOS                                Centos 9  BaseOS

Step 6 : Check by installing any package (say firefox if it is not already installed)

[centos@midas ~]$ sudo yum install firefox
Centos 9  BaseOS                                            8.3 MB/s | 1.6 MB     00:00
Centos 9  AppStream                                          20 MB/s | 5.9 MB     00:00
Last metadata expiration check: 0:00:01 ago on Sat 15 Apr 2023 03:48:19 PM IST.
Dependencies resolved.
============================================================================================
 Package                       Architecture Version             Repository             Size
============================================================================================
Installing:
 firefox                       x86_64       91.11.0-2.el9       Local-AppStream       103 M
Installing dependencies:
 liberation-fonts-common       noarch       1:2.1.3-4.el9       Local-AppStream        15 k
 liberation-sans-fonts         noarch       1:2.1.3-4.el9       Local-AppStream       602 k

Transaction Summary
============================================================================================
Install  3 Packages

Total size: 104 M

Using Local Yum repo for systems across your local network

If you want to use a local yum repo for other systems in your network you can actually host this repo as your FTP or HTTP share.

For this you will first have to configure your vstfpd or httpd (Apache) server, and then host the localrepo directory in /var/ftp/pub or /var/www/html folders.

Then on your other systems in the network you will give the baserul as ftp://<yum local server ip>/<directory name> or http://<yum local server ip>/<directory name> and that’s it, you can now use yum in your network without having any need to access the internet.

.

.

About Upspir

Upspir trains and mentor young professionals to build a strong career in technical support roles. Our training programs covers both technical and employability skills require to succeed in the technical support domains. With our founder’s 16 years of experience in the domain we are working to bridge the gap between supply and demand of technical support talent.

Add a Comment

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