Posted on
Administration

Setting up a local repository for DNF/YUM

Author
  • User
    Linux Bash
    Posts by this author
    Posts by this author

Setting Up a Local Repository for DNF/YUM, and Adjustments for APT and Zypper

Creating a local repository on your Linux system can significantly improve installation time for software packages, reduce bandwidth usage, and provide a reliable backup of software. This is particularly useful in environments where multiple machines need to access the same repository, or a robust setup is required to manage software systematically. Let's dive into how to set up a local repository specifically for Fedora's DNF (or the older YUM), and also touch on settings for APT (used in Debian-based systems) and Zypper (used in openSUSE).

Step 1: Installing HTTP Server

First, you'll need an HTTP server to serve the repository files. Here, we'll use Apache HTTP Server as it's widely supported and easy to configure.

On Fedora or CentOS:

sudo dnf install httpd
sudo systemctl start httpd
sudo systemctl enable httpd

On Debian, Ubuntu:

sudo apt install apache2
sudo systemctl start apache2
sudo systemctl enable apache2

On openSUSE:

sudo zypper install apache2
sudo systemctl start apache2
sudo systemctl enable apache2

Step 2: Creating Repository Directory

Create a directory within your HTTP server’s web serving directory. This directory will hold the repository data.

sudo mkdir -p /var/www/html/repos/myrepo

Step 3: Adding Packages

Now, add RPM packages to this directory. You can either copy existing RPM files from your system or download the packages you need.

sudo cp /path/to/rpmfiles/* /var/www/html/repos/myrepo

Step 4: Creating the Repository

Use the createrepo command to create a repository. This command will generate necessary metadata for your repository.

On Fedora or CentOS:

sudo dnf install createrepo
sudo createrepo /var/www/html/repos/myrepo

On openSUSE (as openSUSE does generally use RPM packages):

sudo zypper install createrepo
sudo createrepo /var/www/html/repos/myrepo

Step 5: Configuring the Client

To use your local repository, you need to point your package manager to it by adding a new repository configuration file.

For DNF or YUM:

Create a .repo file in /etc/yum.repos.d/ (or /etc/dnf/repos.d/ for newer Fedora systems):

sudo vi /etc/dnf/repos.d/myrepo.repo

Add the following:

[myrepo]
name=My Local Repository
baseurl=http://<your-server-ip>/repos/myrepo
enabled=1
gpgcheck=0

Adjustments for APT:

For APT, you’ll need to use a slightly different setup, as APT uses DEB packages instead of RPMs.

echo "deb [trusted=yes] http://<your-server-ip>/repos/myrepo ./" | sudo tee /etc/apt/sources.list.d/myrepo.list
sudo apt update

Adjustments for Zypper:

For Zypper, the process will be similar to DNF/YUM due to its compatibility with RPM packages.

sudo vi /etc/zypp/repos.d/myrepo.repo

Add:

[myrepo]
name=My Local Repository
baseurl=http://<your-server-ip>/repos/myrepo
enabled=1
autorefresh=1
type=rpm-md

Step 6: Testing the Repository

Finally, test your newly configured repository:

For DNF or YUM:

sudo dnf repolist
sudo dnf install some-package

For APT:

sudo apt update
sudo apt install some-package

For Zypper:

sudo zypper refresh
sudo zypper install some-package

Conclusion

Setting up a local repository may seem technical, but it provides great control and efficiency in managing packages across multiple systems. Whether you’re using DNF, APT, or Zypper, each system has robust support for local repositories to help streamline your software management activities. Remember to adjust firewall settings if necessary to allow HTTP traffic, and consider setting up routine backups of your repository data for added reliability.