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.

Steps To Set up a YUM Repository on Centos 7

To set up Yum repositories on Centos 7 you need to log in to your server 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.

Also, you need to set up a basic firewall. To do this, you can follow our guide on Setting up a Firewall with Firewalld on Centos 7.

Step 1 – 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 the Apache web services package to use HTTP on Centos 7 by running the following command:

sudo yum install httpd

If you use FTP, run the following command instead:

sudo yum install vsftpd

Note: Also, you can use Nginx as a web server instead of Apache. You can check our article about Installing Nginx on Centos 7.

Step 2 – Configure Firewall Rules for Yum Repository

At this point, you need to open the correct port on your firewall. 80 for HTTP and 21 for FTP. To do this, you can use the following commands:

sudo firewall-cmd --zone=public --add-port=80/tcp
sudo firewall-cmd --zone=public --add-port=21/tcp

Reload the firewall to apply the new rules:

sudo firewall-cmd --reload

Step 3 – 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!

Step 4 – Create a Directory to Store the Repositories on Centos 7

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

Step 5 – Synchronize HTTP or FTP Repositories on Centos 7

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.

Step 6 – Create a New Repository on Centos 7

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

Step 7 – Set up the Yum Repository on the Linux Client Machine

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

That’s it, you are done.

Conclusion 

At this point, you have learned how to create yum repositories and create a directory to store them, also you have learned to synchronize HTTP and FTP repositories and you can easily 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.

Please subscribe to us on Facebook and Twitter.

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!