In this guide, you will learn to Create a Local Repository on AlmaLinux 9 or RHEL 9.
A local repository is useful when a system doesn’t have access to an internet connection. Or when a system admin wants to manage the software package locally in a closed network, a local repository comes in.
The local repository is used for package installation, management, and update.
Now follow the steps below to create a local repo on AlmaLinux 9 or RHEL 9.
How To Create a Local Repository on AlmaLinux 9?
To complete this guide, you must have access to your server as a non-root user with sudo privileges. To do this, you can visit this guide on Initial Server Setup with AlmaLinux 9.
Step 1 – Install Git on AlmaLinux 9
First, you need to update your local package index. Run the system update with the following command:
sudo dnf update -y
Then, install Git on your server by using the following command:
sudo dnf install git -y
Verify your Git installation by checking its version:
Output git version 2.39.3
Step 2 – Create a Local Repository on RHEL / AlmaLinux 9
At this point, you can use the command below to create your local repo. To do this, you can use the command below:
Then, switch to your created directory with the command below:
Next, use the following Git command to initialize the new Git repository:
sudo git init
In your output, you will see:
Output hint: Using 'master' as the name for the initial branch. This default branch name hint: is subject to change. To configure the initial branch name to use in all hint: of your new repositories, which will suppress this warning, call: hint: hint: git config --global init.defaultBranch <name> hint: hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and hint: 'development'. The just-created branch can be renamed via this command: hint: hint: git branch -m <name> Initialized empty Git repository in /root/local-repos/.git/
Switch back to your home directory with the command below:
Next, you can copy your desired files into the local-repos directory. For example, we copy the Documents directory to our local repo on AlmaLinux 9:
cp -r ~/Documents ~/local-repos
Again, switch to your Local repository:
Then, use the command below to stage all the available files:
git add *
Here you can create your first commit with the Git command:
git commit -m "Initial commit"
Also, you can use the createrepo command. But first, you need to install it on your AlmaLinux server by using the command below:
sudo dnf install createrepo
At this point, you have learned to use the Git command to create a local repository on your AlmaLinux 9 or RHEL 9. You can use the local repository to manage your software packages locally in a closed network.
Hope you enjoy it. You may be interested in these articles: