Creating Package-Specific Local Repository in Rocky Linux 9
Tags: rockylinux9, postgres, localrepository
Published: 2024-01-21 12:47:09


This document explains how to create a package-specific local repository for the installation of PostgreSQL-16 from a local repository.

First, let's install the necessary packages to download and create repositories:

```console
dnf install -y yum-utils createrepo
```

At this stage, we can download all the dependencies for PostgreSQL-16, along with their sub-dependencies, using the `repotrack` command. Ensure that the desired packages are available for download.

Now, add the PostgreSQL repositories to the system for PostgreSQL-16 to be downloaded:

```console
sudo dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
```

You can confirm the availability of the package(s) for download using the `dnf search package_name` command:
![search](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s8glb81i4gfpjij7wa8l.png)

Once you've confirmed the availability, you can start the download process. 

You can specify the download directory using the `repotrack` command; otherwise, it will download to the current directory.

Use the following command to download the necessary packages for `postgresql16-server` to the **/var/www/html/repos/postgres** directory:

```console
repotrack --downloaddir=/var/www/html/repos/postgres postgresql16-server
```

After the download, convert the downloaded RPM packages into a repository format using the `createrepo` command:

```console
createrepo /var/www/html/repos/postgres
```
![createrepo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/htvlzvvafdul8ci4mkpq.png)

After this step, you'll observe that a folder named repodata has been created under **/var/www/html/repos/postgre**.

Now, we can define the created repository to the Linux system. To do this, we need to remove the old repository definitions first for our changes to take effect.

```console
mkdir -p /etc/yum.repos.d/old
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/old/
```

With the above steps, we moved all old repository definitions to the **/etc/yum.repos.d/old** directory. Now, let's create our own repository definition file.

```console
vi /etc/yum.repos.d/local-postgres.repo
```

In the VI editor, save and exit after entering the following text into the file:

```
[LocalRepository-PostgreSQL16]
name=RL9 - Local PostgreSQL16-Server Repository
metadata_expire=-1
gpgcheck=0
enabled=1
baseurl=file:///var/www/html/repos/postgres
```

If we read the file using the `cat` command, the output should look like the following:
![cat](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gf48ay3rvd6mo3micpnw.png)

After these steps, to activate our repository, we need to clean the caches of the dnf package manager and rescan the repo list. We can do this with the following commands:

```console
dnf clean all
dnf update
```

Let's view our repo using the `dnf repolist` command:
![repolist](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iw4i2xt3ka4bp2v17ob3.png)

Finally, let's verify the correctness of the actions taken by installing `postrgesql16-server` from the local repository:

```console
dnf install postgresql16-server
```
![installation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/60a7r60xiskl4a4yw7aj.png)

The installation process has been successfully completed! The red box indicates that all the necessary packages were installed from the local repository.

<sub>Translated By ChatGPT3.5</sub>