Share your love
Create a Local Repository on AlmaLinux 9 / RHEL 9
In this guide, you will learn to Create a Local Repository on AlmaLinux 9 / RHEL 9 Such as Rocky Linux 9. A local repository is useful when a system doesn’t have access to an internet connection. 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 updates.
Now follow the steps below to create a local repo on AlmaLinux 9 or RHEL 9.
Steps To Create a Local Repository on AlmaLinux 9 / RHEL 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 the following RHEL 9 initial guides:
Initial Server Setup with AlmaLinux 9
Initial Server Setup with Rocky Linux 9
In this guide, to show you the guide steps we use AlmaLinux 9 server.
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:
git --version
Output
git version 2.39.3
Step 2 – Create a Local Repo on RHEL 9 / AlmaLinux 9 / Rocky Linux 9
At this point, you can use the command below to create your local repo. To do this, you can use the command below:
mkdir local-repos
Then, switch to your created directory with the command below:
cd ~/local-repos
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:
cd
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:
cd ~/local-repos
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
Conclusion
At this point, you have learned to use the Git command to create a local repository on your AlmaLinux 9 or RHEL 9 such as Rocky Linux 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: