Are you a DevOps Engineer, System Administrator, or System Engineer looking to set up your own custom Linux repository for downloading dependencies or installing software? This guide will walk you through the process of creating a local repository, specifically using CentOS 7, although the steps are applicable to other Linux distributions as well.
Why Create a Local Repository?
With CentOS 7 reaching its end of support in June 2024, you may find it difficult to install dependencies or download software from the official yum repositories. Setting up a self-managed local repository allows you to continue accessing necessary packages without needing an internet connection.
Steps to Create a Local Repository
Download the .iso Image from the official page of Centos
Download the .iso image of your current installed operating system (CentOS 7).
Create a Directory
Create a directory in the root directory to mount the .iso image. For example:
sudo mkdir -p /repository
Mount the .iso Image
Mount the .iso image to the created directory:
sudo mount /path/to/CentOS-7-x86_64-DVD-1602-99.iso /repository/
Create a Repository File
Create a repository file in the default repository directory:
sudo vi /etc/yum.repos.d/local-repo.repo
Add Repository Configuration
Paste the following configuration into the file and save it:
[localrepo]
name=Local Repository
baseurl=file:///repository
enabled=1
gpgcheck=0
Update Repository List
Update the repository list to include the new local repository:
sudo yum repolist
The new local repository should now appear in the list of repositories.
(Optional) Clean Up Repository Files
If desired, remove all other repository files in the /etc/yum.repos.d/ directory except for files starting with epel.*.
sudo rm /etc/yum.repos.d/* && sudo mv /etc/yum.repos.d/epel.* /etc/yum.repos.d/
Conclusion
Congratulations! You should now be able to download all the dependencies and software you need from your local repository without needing to connect to the internet. This setup ensures you have a reliable source for packages, especially useful for environments with restricted internet access or for maintaining consistent package versions.