Saturday, September 24, 2022

How to Set up a YUM repository on Centos 7

In this article, we want to teach you How to set up a YUM repository on Centos 7.

A Linux repository is a storage location from which your system gets back and installs OS updates and applications. Each repository is a collection of software hosted on a remote server and intended to be used for installing and updating software packages on Linux systems.

Yum is a free and open-source command-line package-management utility for computers running the Linux operating system using the RPM Package Manager.

How to Set up a YUM repository on Centos 7

To set up Yum repositories on Centos 7 you need to log in as a non-root user with sudo permissions.

If you don’t know how to do that check our article about the Initial server setup with Centos 7.

Configure Network access on Centos 7

You need to configure the system for network access. Yum typically delivers files over FTP or HTTP.

If you have configured an Apache web server or an FTP server follow these steps:

Install Apache web services package to use HTTP on Centos 7, run the following command:

sudo yum install httpd

If you use FTP run the following command instead:

sudo yum install vsftpd

Note: Open the correct port on your firewall. 80 for HTTP and 21 for FTP. Also, you can use Nginx as a web server instead of Apache.

You can check our article about how to install Nginx on Centos 7.

How to Create a YUM repository on Centos 7

To create a YUM repository you can use the “createrepo” software package. run the following command:

sudo yum install createrepo

Enter “y” to download the package. you will see something like this in your output:

Otput
Installed:
createrepo.noarch 0:0.9.9-28.el7
Dependency Installed:
deltarpm.x86_64 0:3.6-3.el7 python-deltarpm.x86_64 0:3.6-3.el7
Complete!

How to Create a Directory to Store the Repositories

At this point, you need to create a directory to store the repositories.

For an HTTP repository run the following command:

sudo mkdir –p /var/www/html/repos/{base,centosplus,extras,updates}

For an FTP repository, run the command below:

sudo mkdir –p /var/ftp/repos

How to Synchronize HTTP Repositories

Here you need to download a local copy of the official CentOS repositories to your server. This allows systems on the same network to install updates more efficiently.

Run the commands below:

sudo reposync -g -l -d -m --repoid=base --newest-only --download-metadata --download_path=/var/www/html/repos/
sudo reposync -g -l -d -m --repoid=centosplus --newest-only --download-metadata --download_path=/var/www/html/repos/
sudo reposync -g -l -d -m --repoid=extras --newest-only --download-metadata --download_path=/var/www/html/repos/
sudo reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/var/www/html/repos/

Note: If you are using FTP, replace your FTP directory in the commands above.

How to Create a New Repository

You can use ‘createrepo’ to create a repository on Centos 7.

To create a repository for HTTP run the command below:

sudo createrepo /var/www/html

You can use the following command for FTP:

sudo createrepo /var/ftp

Set up Yum Repository on Client System

You need to switch to the client system and log in as a non-root user with sudo permissions.

Then, you’ll need to prevent yum from downloading from the wrong location. To do this, move the default yum repository files with the following command:

mv /etc/yum.repos.d/*.repo /tmp/

Here you can create and edit a new config file with the below command:

sudo vi /etc/yum.repos.d/remote.repo

When you get into the file put these commands in it:

[remote] 
name=RHEL Apache 
baseurl=http://your-IP-address
enabled=1 
gpgcheck=0

Save and close the file.

Note: For FTP you should replace the Apache and HTTP with FTP in the commands above.

Now you can test the configuration in your client system. run a command to install a package with YUM. for example:

sudo yum install httpd

Conclusion 

At this point, you learn how to create yum repositories and create a directory to store them, you learn to synchronize HTTP and FTP repositories and you can set up a yum repository on a client system.

Hope you enjoy this article about How to set up a YUM repository on Centos 7.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular