Introduction
This article will show how to create a local repository in Linux CentOS 8. Actually, there is a slight trouble upon installing a package. It is when executing one simple install package using yum ends in failure. It is because of the connection problem. So, after several trial attempts, the installation end in failure. So, the process of downloading the package is always disconnected or terminated. In order to install the package, there is another simple way to do it. Instead of having to download the package from a remote repository, just download it from a local one. So, the main reason for creating a local repository in this article is to overcome the failure of the download step on installing a certain package using ‘yum’ or ‘dnf’.
Create a Local Repository in Linux CentOS 8
The Reason
Actually, the reason for creating a local repository in Linux CentOS 8 is because of the failure in installing a package. The package name is ‘jenkins’. So, the following are steps for installing ‘jenkins’ end in failure :
-
Just access the server or the machine. Either by local access or remote. This article is using a virtual server running in a VirtualBox application. So, remote access using SSH protocol is a convenient way to do it. For reference, read the article with the title ‘How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH’ in this link.
Microsoft Windows [Version 10.0.19042.1052] (c) Microsoft Corporation. All rights reserved. C:\Users\Personal>ssh -p 9922 admin@localhost admin@localhost's password: Activate the web console with: systemctl enable --now cockpit.socket Last login: Sun Jun 20 09:51:37 2021 from 10.0.2.2 [admin@localhost ~]$
-
Next, in order to keep it short, the following is the command line interface of the server using root account :
[admin@localhost ~]$ sudo su - [sudo] password for admin: Last login: Sun Jun 20 09:52:43 EDT 2021 on pts/1 [root@localhost ~]#
-
So, there is a package with the name of ‘jenkins’. Installing it for several times end in failure as follows :
[root@localhost yum.repos.d]# yum -y install jenkins Last metadata expiration check: 0:01:03 ago on Mon 21 Jun 2021 10:33:49 AM EDT. Dependencies resolved. ======================================================================================================================== Package Architecture Version Repository Size ========================================================================================================================Installing: jenkins noarch 2.289.1-1.1 jenkins 71 M Transaction Summary ========================================================================================================================Install 1 Package Total download size: 71 M Installed size: 71 M Downloading Packages: [MIRROR] jenkins-2.289.1-1.1.noarch.rpm: Curl error (28): Timeout was reached for https://mirrors.xxxx.xxxxxxxx.edu.xx/jenkins/redhat-stable/jenkins-2.289.1-1.1.noarch.rpm [Connection timed out after 30952 milliseconds] [MIRROR] jenkins-2.289.1-1.1.noarch.rpm: Curl error (28): Timeout was reached for https://mirrors.xxxx.xxxxxxxx.edu.cn/jenkins/redhat-stable/jenkins-2.289.1-1.1.noarch.rpm [Connection timed out after 30695 milliseconds] [MIRROR] jenkins-2.289.1-1.1.noarch.rpm: Curl error (28): Timeout was reached for https://mirrors.xxxx.xxxxxxxx.edu.cn/jenkins/redhat-stable/jenkins-2.289.1-1.1.noarch.rpm [Connection timed out after 30550 milliseconds] [MIRROR] jenkins-2.289.1-1.1.noarch.rpm: Curl error (28): Timeout was reached for https://mirrors.xxxx.xxxxxxxx.edu.cn/jenkins/redhat-stable/jenkins-2.289.1-1.1.noarch.rpm [Connection timed out after 30686 milliseconds] [FAILED] jenkins-2.289.1-1.1.noarch.rpm: No more mirrors to try - All mirrors were already tried without success The downloaded packages were saved in cache until the next successful transaction. You can remove cached packages by executing 'yum clean packages'. Error: Error downloading packages: Cannot download jenkins-2.289.1-1.1.noarch.rpm: All mirrors were tried [root@localhost yum.repos.d]#
The Solution
This part will focus on showing how to create a local repository to solve the problem. The following are those steps :
-
Just access the location which is going to be location of the local repository where the files for package isntallation exist. In this context, it is in ‘/opt/local’. So, access ‘/opt’ and create a folder with the name of ‘local’ as follows :
[root@localhost opt]# mkdir local [root@localhost opt]# cd local/ [root@localhost local]# ls jenkins-2.235.1-1.1.noarch.rpm repodata [root@localhost local]#
-
Copy the package from another place. Actually, search the package name in google and comes up with another link. Use wget to download it by executing the following command :
[root@localhost local]# wget https://ftp.osuosl.org/pub/jenkins/redhat-stable/jenkins-2.235.5-1.1.noarch.rpm --2021-06-21 11:16:00-- https://ftp.osuosl.org/pub/jenkins/redhat-stable/jenkins-2.235.5-1.1.noarch.rpm Resolving ftp.osuosl.org (ftp.osuosl.org)... 64.50.236.52, 140.211.166.134, 64.50.233.100, ... Connecting to ftp.osuosl.org (ftp.osuosl.org)|64.50.236.52|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 66270257 (63M) [application/x-rpm] Saving to: ‘jenkins-2.235.5-1.1.noarch.rpm’ jenkins-2.235.5-1.1.noarch.rpm 100%[=======================================================>] 63.20M 290KB/s in 6m 35s 2021-06-21 11:22:36 (164 KB/s) - ‘jenkins-2.235.5-1.1.noarch.rpm’ saved [66270257/66270257] [root@localhost local]#
-
After that, check whether the downloaded file is actually exist by typing the command as follows :
[root@localhost local]# ls -al total 64688 drwxr-xr-x 2 root root 44 Jun 21 11:01 . drwxr-xr-x. 9 root root 201 Jun 18 05:01 .. -rw-rw-r-- 1 admin admin 66238847 Jun 18 05:02 jenkins-2.235.1-1.1.noarch.rpm [root@localhost local]#
-
Continue on, just execute the following command to create the repository :
[root@localhost local]# createrepo . Directory walk started Directory walk done - 1 packages Temporary output repo path: ./.repodata/ Preparing sqlite DBs Pool started (with 5 workers) Pool finished [root@localhost local]#
-
Following after, just check the content of the folder to see whether the folder initilialization into a local repository is a success :
[root@localhost local]# ls -al total 64692 drwxr-xr-x 3 root root 60 Jun 21 11:01 . drwxr-xr-x. 9 root root 201 Jun 18 05:01 .. -rw-rw-r-- 1 admin admin 66238847 Jun 18 05:02 jenkins-2.235.1-1.1.noarch.rpm drwxr-xr-x 2 root root 4096 Jun 21 11:01 repodata [root@localhost local]#
-
Create a repository file representing the local repository created in the previous step. The location is in ‘/etc/yum.repos.d’ with the name of ‘local.repo’ as an example. The following is the execution of it continue on filling the content of the file to define the local repository :
[root@localhost local]# cd /etc/yum.repos.d [root@localhost yum.repos.d]# touch local.repo [root@localhost yum.repos.d]# vim local.repo
Adjust the content of the file according to the environment of the server or the machine. Primarily, the value of the ‘baseurl’ definition. Since the location of the local repository is in ‘/opt/local’, just fill the value for the ‘baseurl’ into ‘file:///opt/local’.
[local] name=CentOS Linux 8 - Local metadata_expire=-1 gpgcheck=0 enabled=1 baseurl=file:///opt/local/ gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
-
Execute the following command to clean up the yum repository :
[root@localhost yum.repos.d]# yum clean all 0 files removed [root@localhost yum.repos.d]#
-
Next, just execute the following command to list the available yum repository. Make sure that the local repository exist in the yum repository :
[root@localhost local]# yum repolist repo id repo name local CentOS Linux 8 - Local [root@localhost local]#
-
Finally, install the package which in the first place is needed by execute the previous command again :
[root@localhost local]# yum -y install jenkins CentOS Linux 8 - Local 1.4 MB/s | 1.4 kB 00:00 Last metadata expiration check: 0:00:01 ago on Mon 21 Jun 2021 12:07:54 PM EDT. Dependencies resolved. ================================================================================================================================ Package Architecture Version Repository Size ================================================================================================================================ Installing: jenkins noarch 2.235.5-1.1 local 63 M Transaction Summary ================================================================================================================================ Install 1 Package Total size: 63 M Installed size: 63 M Downloading Packages: Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: jenkins-2.235.5-1.1.noarch 1/1 Installing : jenkins-2.235.5-1.1.noarch 1/1 Running scriptlet: jenkins-2.235.5-1.1.noarch 1/1 Verifying : jenkins-2.235.5-1.1.noarch 1/1 Installed: jenkins-2.235.5-1.1.noarch Complete! [root@localhost local]#