Creating Your Own Local Package Repositories in Linux.

Creating Your Own Local Package Repositories in Linux.

Do you have a collection of packages you want to manage locally and make available through your own repository? With a local repository, you can use your package manager to easily install these packages as needed.

This can be achieved using the createrepo command-line tool, which allows you to turn any directory into a repository.

Make sure createrepo tool is installed locally in your system. I am using RockyLinux9 operating system for this case.
dnf install createrepo_c

It's a good idea to keep your RPMs organized in a dedicated folder. In this example, I'll be creating the libadd RPM using this post.

You can use a folder like /var/opt/localrepo as your local repository, or choose any other location that suits you. Simply create a folder and place your RPMs there. I'll be using this path as my local repository, but feel free to pick a directory that works best for your setup.

[root@Rohit ~]# mkdir /var/opt/localrepo
[root@Rohit ~]# cp /home/rohit/workspace/LibAdd/source-rpm/libadd-1.0-1.x86_64-devel.rpm /var/opt/localrepo/
[root@Rohit ~]# cp /home/rohit/workspace/LibAdd/source-rpm/libadd-1.0-1.x86_64-lib.rpm /var/opt/localrepo/
[root@Rohit ~]#
[root@Rohit ~]# tree /var/opt/localrepo/
/var/opt/localrepo/
├── libadd-1.0-1.x86_64-devel.rpm
└── libadd-1.0-1.x86_64-lib.rpm

0 directories, 2 files
[root@Rohit ~]#

Create a local.repo file inside the /etc/yum.repos.d folder. As this folder contains all the repository details.

put the below data in local.repo

[local]
name=local repo
baseurl=file:///var/opt/localrepo
enabled=1

Run createrepo command to create the repo. createrepo /var/opt/locarepo

[root@Rohit ~]# createrepo /var/opt/localrepo/
Directory walk started
Directory walk done - 2 packages
Temporary output repo path: /var/opt/localrepo/.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished
[root@Rohit ~]#

Now, dnf or yum should include your local repository when listing all enabled repositories. dnf repolist

[root@Rohit ~]# dnf repolist
Repository devel is listed more than once in the configuration
repo id                                               repo name
appstream                                             Rocky Linux 9 - AppStream
baseos                                                Rocky Linux 9 - BaseOS
epel                                                  Extra Packages for Enterprise Linux 9 - x86_64
epel-cisco-openh264                                   Extra Packages for Enterprise Linux 9 openh264 (From Cisco) - x86_64
extras                                                Rocky Linux 9 - Extras
local                                                 local repo

To verify that the libadd package is available from your local repository, run the following command: dnf list | grep libadd

This will filter the output and show you if the libadd package is being sourced from your local repository. In this case, it confirms that the package is being pulled from the local repo you've set up.

[root@Rohit ~]# dnf list | grep libadd
Repository devel is listed more than once in the configuration
libadd-devel.x86_64                                                                      1.0-1                                local
libadd-lib.x86_64                                                                        1.0-1                                local
[root@Rohit ~]#

You can continue to expand your local repository by adding more RPM packages to the same folder. After doing so, don’t forget to update the repository metadata, so dnf or yum can recognize the new additions. To do this, run:

createrepo --update /var/opt/localrepo

Read more