Recreate Yum Package Manager Repository File

Posted on

Having a host, server or workstation installed with CentOS Linux operating system with an empty directory of ‘yum.repos.d’ is quite devastating since several utilities or packages need to be installed using yum package manager.

In CentOS or any Redhat operating system variant which has the same flavor, yum package manager is used to manage package, utility or application in it.

To be able to install a new package, utility or application, the operating system provide a way to perform it by using yum package manager utility. It is actually a tool which can be executed in a command line. To be able to install a new package, yum needs to refer to file used for repository description which ends with .repo extension and it is saved by default in /etc/yum.repos.d directory.

CentOS operating system in this case provides several default file repository which can be used for installing packages or utilities considered as basic needs, requirement or features.

One of that file normally named ‘CentOS-Base.repo’ and generally it exist after the end of fresh and new installation of CentOS operating system.

In any circumstances where repository list shown there are no repository defined which is shown from the following command execution :

yum repolist

Below is the output of the above command’s execution :

[root@centos yum.repos.d]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repolist: 0
[root@centos yum.repos.d]#

Whenever those files were deleted accidentally or in certain situation those files are not exist anymore, it can be recreated by performing the following steps :

1. Go to the default repository file definition’s directory located in /etc/yum.repos.d :

[root@hostname ~]# cd /etc/yum.repos.d
[root@hostname yum.repos.d]#

2. Create a new file named CentOS-Base.repo by executing the following command :

touch CentOS-Base.repo

For an example :

[root@hostname yum.repos.d]# touch CentOS-Base.repo
[root@hostname yum.repos.d]# ls -al | grep CentOS-Base.repo
-rw-------.  1 root root 2487 Dec 16 11:11 CentOS-Base.repo
[root@hostname yum.repos.d]# 

3.Fill the newly created file with the following content :

#
# This file uses a new mirrorlist system developed by Lance Davis for CentOS.
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
protect=1
enabled=1

#released updates 
[update]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
protect=1

#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
#baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
protect=1

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=1
protect=1

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=2
protect=1

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
priority=2
protect=1

4. After inserting the above content to the newly created ‘CentOS-Base.repo’ file and save it, run the previous executed command to see whether the repository has successfully recognized by yum :

yum repolist

Below is the output of the above command :

[root@centos yum.repos.d]# yum repolist
repo id                          repo name                     status                                                                                
addons/7/x86_64                  CentOS-7 - Addons             0                                                                                      
base/7/x86_64                    CentOS-7 - Base               9.363                                                                                  
extras/7/x86_64                  CentOS-7 - Extras             435                                                                                    
update/7/x86_64                  CentOS-7 - Updates            391                                                                                    
repolist: 10.189
[root@centos yum.repos.d]# 

Start using it by installing some package or tool as shown below which is executing the installatio process of ‘wget’ utility for download :

[root@hostname yum.repos.d]# yum -y install wget
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-13.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================================================================================
Package     Arch          Version        Repository              Size
=====================================================================================================================================================================================================================
Installing:
wget        x86_64        1.14-13.el7    base                    546 k

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

Total download size: 546 k
Installed size: 2.0 M
Downloading packages:
wget-1.14-13.el7.x86_64.rpm                          | 546 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : wget-1.14-13.el7.x86_64                                1/1
Verifying  : wget-1.14-13.el7.x86_64                                1/1

Installed:
wget.x86_64 0:1.14-13.el7

Complete!
[root@hostname yum.repos.d]#
 

One thought on “Recreate Yum Package Manager Repository File

Leave a Reply