Cyberithub

How to Setup Local YUM Repository on CentOS 7 Using 8 Easy Steps

Advertisements

In this article, I will take you through the Steps to setup local YUM Repository on Linux (RHEL / CentOS 7) Using 8 Easy Steps. Many times you might have observed that few of the Critical or Production Servers which resides in a Secure Network Environment does not have access to Public Network. Hence if someone want to update the CentOS version they cannot use the yum command to update his Server CentOS version from Internet. For that purpose you need to setup a Local YUM Repository using a CentOS Image and then update your System from that local repository. I will go through the steps to setup Local YUM Repository in below section.

How to Setup Local YUM Repository on CentOS 7 Using 8 Easy Steps 1

Setup Local YUM Repository on Linux

Also Read: Top 12 Nginx Commands Every Linux Admin Should Know

Step 1: Prerequisites

a) You should have a running CentOS 7 System.

b) You should have CentOS 7.8 Minimal ISO Image Available in the System. You can download ISO Image from CentOS Official Download website.

c) You should have sudo access to run privilege commands. You can check How to Add User to Sudoers to provide sudo access to User.

d) You should have yum command installed in your System. You can check Top 22 YUM Command Examples in RedHat / CentOS 7 to know more about yum.

Step 2: Check Your Current CentOS Version

In our setup we have  CentOS 7.7.1908 installed as can be seen from /etc/redhat-release output which we will upgrade to latest CentOS 7.8.2003(at the time of writing this article) Release.

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)

Step 3: Mount CentOS 7.8.2003 ISO Image

Before mounting the ISO Image locally you need to first setup the directory path where you want to mount the image. Here I am creating a iso directory under /mnt path using mkdir /mnt/iso command and then mounting the ISO Image in read-only using mount -o loop CentOS-7-aarch64-Minimal-2003.iso /mnt/iso command as shown below.

[root@localhost ~]# mkdir /mnt/iso
[root@localhost ~]# mount -o loop CentOS-7-aarch64-Minimal-2003.iso /mnt/iso
mount: /dev/loop0 is write-protected, mounting read-only

Step 4: Create the Repo File

Now you need to create a repo file where you need to specify the ISO Image mount point and other relevant details to download the packages from baseurl.

[root@localhost ~]# vi /etc/yum.repos.d/centos.repo
[CentOS7-Repo]
name=CentOS7 Server
baseurl=file:///mnt/iso
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
gpgcheck=1

Step 5: Cleanup and List All YUM Repository

After setting up the YUM Repository you need to first perform the clean up using yum clean all command as shown below. This command will remove Cache of all the enabled YUM repositories.

[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base centos7-Server extras updates
Cleaning up list of fastest mirrors

Then you can list the repo id of all the YUM Repository that can be enabled or disabled using yum repolist enabled command as shown below.

[root@localhost ~]# yum repolist enabled
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: d36uatko69830t.cloudfront.net
* extras: d36uatko69830t.cloudfront.net
* updates: d36uatko69830t.cloudfront.net
base | 3.6 kB 00:00:00
centos7-Server | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/6): CentOS7-Repo/group_gz | 3.5 kB 00:00:00
(2/6): base/7/x86_64/group_gz | 153 kB 00:00:00
(3/6): centos7-Server/primary_db | 724 kB 00:00:00
(4/6): extras/7/x86_64/primary_db | 205 kB 00:00:00
(5/6): updates/7/x86_64/primary_db | 3.0 MB 00:00:00
(6/6): base/7/x86_64/primary_db | 6.1 MB 00:00:00
repo id repo name status
base/7/x86_64 CentOS-7 - Base 10,070
centos7-Server CentOS7 Server 443
extras/7/x86_64 CentOS-7 - Extras 412
updates/7/x86_64
repolist: 11,825

Step 6: Update Your System Using Local YUM Repository

Once repository is enabled you can download the updates by using below yum command where we are disabling all the other Repos except the one we just configured to avoid any unnecessary checking. Below yum command will check and download all the updates from CentOS7-Repo repository as shown below.

[root@localhost ~]# yum --disablerepo=* --enablerepo=CentOS7-Repo update 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package elfutils-default-yama-scope.noarch 0:0.176-2.el7 will be updated
---> Package elfutils-default-yama-scope.noarch 0:0.176-4.el7 will be an update
---> Package grub2-common.noarch 1:2.02-0.80.el7.centos will be updated
--> Processing Dependency: grub2-common = 1:2.02-0.80.el7.centos for package: 1:grub2-tools-minimal-2.02-0.80.el7.centos.x86_64
--> Processing Dependency: grub2-common = 1:2.02-0.80.el7.centos for package: 1:grub2-pc-2.02-0.80.el7.centos.x86_64
--> Processing Dependency: grub2-common = 1:2.02-0.80.el7.centos for package: 1:grub2-tools-2.02-0.80.el7.centos.x86_64
--> Processing Dependency: grub2-common = 1:2.02-0.80.el7.centos for package: 1:grub2-tools-extra-2.02-0.80.el7.centos.x86_64
---> Package grub2-common.noarch 1:2.02-0.81.el7.centos will be an update
---> Package grub2-pc-modules.noarch 1:2.02-0.80.el7.centos will be updated
--> Processing Dependency: grub2-pc-modules = 1:2.02-0.80.el7.centos for package: 1:grub2-pc-2.02-0.80.el7.centos.x86_64
---> Package grub2-pc-modules.noarch 1:2.02-0.81.el7.centos will be an update
---> Package iwl7260-firmware.noarch 0:25.30.13.0-76.el7 will be obsoleting
---> Package iwl7265-firmware.noarch 0:22.0.7.0-72.el7 will be obsoleted
---> Package python-urlgrabber.noarch 0:3.10-9.el7 will be updated
---> Package python-urlgrabber.noarch 0:3.10-10.el7 will be an update
---> Package selinux-policy.noarch 0:3.13.1-252.el7_7.6 will be updated
---> Package selinux-policy.noarch 0:3.13.1-266.el7 will be an update
---> Package selinux-policy-targeted.noarch 0:3.13.1-252.el7_7.6 will be updated
---> Package selinux-policy-targeted.noarch 0:3.13.1-266.el7 will be an update
---> Package setup.noarch 0:2.8.71-10.el7 will be updated
---> Package setup.noarch 0:2.8.71-11.el7 will be an update
---> Package tuned.noarch 0:2.11.0-5.el7_7.1 will be updated
---> Package tuned.noarch 0:2.11.0-8.el7 will be an update
---> Package yum.noarch 0:3.4.3-163.el7.centos will be updated
---> Package yum.noarch 0:3.4.3-167.el7.centos will be an update
---> Package yum-plugin-fastestmirror.noarch 0:1.1.31-52.el7 will be updated
---> Package yum-plugin-fastestmirror.noarch 0:1.1.31-53.el7 will be an update

Step 7: Check the Updated CentOS Version

After successful update if you again check the CentOS version then you can see it is now updated to 7.8.2003 from previous 7.7.1908 version as shown below.

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)

Step 8: Unmount the Image and Remove the Repo file

Once update is complete you can unmount the ISO image from /mnt/iso path using umount /mnt/iso command and delete the created yum repository using rm -rf /etc/yum.repos.d/centos.repo command as shown below.

[root@localhost ~]# umount /mnt/iso/
[root@localhost ~]# rm -rf /etc/yum.repos.d/centos.repo

 

 

Popular Recommendations:-

How to Disable IPV6 on Linux (CentOS / RHEL 7/8) Using 4 Best Steps

52 Useful cut command in Linux/Unix with Examples for Beginners

Introduction to SQL Injection Attacks in MySQL (v5.5)

How to Create Table in MySQL 5.5 with Easy Steps

How to Limit CPU Limit of a Process Using CPULimit in Linux (RHEL/CentOS 7/8)

How to Install Rust Programming Language in Linux Using 6 Best Steps

How to Setup YUM Repository for Locally Mounted DVD on RHEL 7

Openssl Tutorial: Generate and Install Certificate on Apache Server in 8 Easy Steps

How to Enable or Disable SELinux Temporarily or Permanently on RedHat/CentOS 7/8

Top 12 Nmap Commands to Scan Remote Host with Best Practices

Leave a Comment