Linux: Exploring Linux Repositories & creating our own local repository.

 


Introduction:

Linux repositories play a crucial role in the world of Linux distributions by serving as centralized hubs for software packages. They provide a convenient way to install, update, and manage software on your system. In this blog post, we'll look into Linux repositories, covering both local and internet repositories.


Understanding Linux Repositories:


[A] What is a Linux Repository?

A Linux repository is a centralized storage location that houses software packages, along with metadata that describes the packages and their dependencies. Repositories simplify the process of software installation and updates on Linux systems.


[B] Types of Linux Repositories:

 1) Local Repositories:

Local repositories are repositories that exist on your machine or within your local network. They are especially useful in environments with restricted internet access or when you want to control which software versions are available.

[To create a local repository, follow the steps which i have mentioned in Practical below]

2) Internet Repositories:

Internet repositories are hosted on remote servers and provide access to a vast array of software. Popular examples include the official repositories for distributions like Debian, Ubuntu, CentOS, and others.


[C] Enabling and Disabling Repositories:

Use configuration files under /etc/yum.repos.d/ to enable or disable repositories based on your needs.

For example, in yum, modify the enabled=1 parameter in the repository configuration file to enable the repository.


[D] Repository Priority:

Assign priorities to repositories to control which one takes precedence in case of conflicting packages.

For example, in yum, modify the priority=1 parameter in the repo configuration which needs to be call before other repos.


Conclusion:

Linux repositories are the backbone of package management on Linux systems, providing a seamless way to install and update software. Whether you opt for local repositories for greater control or internet repositories for convenience, understanding how to manage repositories is essential for any Linux user or administrator.

------------------------------------------------------------------------------------------------------------------------


Practical :


In this practical,we will create our own local repository in yum.


Create Baseurl path,where you will store your packages.

[root@server1 ~]# mkdir /usr/share/shubham/


Now,copy any packages under the directory which you have created to store the packages,

(NOTE: In yum, all rpm packages are in stored under /var/cache/yum/ directory. For more information,you can check /etc/yum.conf file)


[root@server1 ~]# grep -i cache /etc/yum.conf 

cachedir=/var/cache/yum/$basearch/$releasever

keepcache=1


Now, go to yum package path and copy any package in your repo path,

{Note: you can download package only by skipping its installation by #yum install --downloadonly stress }


[root@server1 shubham]# cd /var/cache/yum/x86_64/7/epel/packages/

[root@server1 packages]# ll

-rw-r--r-- 1 root root 40016 Apr 22  2017 stress-1.0.4-16.el7.x86_64.rpm


[root@server1 packages]# cp stress-1.0.4-16.el7.x86_64.rpm /usr/share/shubham/


Now create the repo,

[root@server1 shubham]# createrepo .

Spawning worker 0 with 2 pkgs

Workers Finished

Saving Primary metadata

Saving file lists metadata

Saving other metadata

Generating sqlite DBs

Sqlite DBs complete


After creating repo, repodata file will get created in same location,

[root@server1 shubham]# ll

drwxr-xr-x 2 root root     4096 Dec 24 11:09 repodata

-rw-r--r-- 1 root root    40016 Dec 24 11:08 stress-1.0.4-16.el7.x86_64.rpm


Now,create your own yum repo configuration under /etc/yum.repos.d/


[root@server1 shubham]# cd /etc/yum.repos.d/

[root@server1 yum.repos.d]# vi shubhamtest.repo

[root@server1 yum.repos.d]# cat /etc/yum.repos.d/shubhamtest.repo 

[shubhamrepo]

name=ShubhamRepo

baseurl=file:///usr/share/shubham

enabled=1

gpgcheck=0

priority=1 -----> [optional field]


Now, run below command to list the all repos,

[root@server1 yum.repos.d]# yum repolist


Now, install the package which you have copied in your repo path i.e /usr/share/shubham/

[root@server1 repodata]# yum install stress


Loaded plugins: fastestmirror

Loading mirror speeds from cached hostfile

 * base: centos.mirror.net.in

 * extras: centos.mirror.net.in

 * updates: centos.mirror.net.in

Resolving Dependencies

--> Running transaction check

---> Package stress.x86_64 0:1.0.4-16.el7 will be installed

--> Finished Dependency Resolution


Dependencies Resolved


=======================================================================================================================================

 Package                      Arch                         Version                             Repository                         Size

=======================================================================================================================================

Installing:

 stress                       x86_64                       1.0.4-16.el7                        shubhamrepo                        39 k


Transaction Summary

=======================================================================================================================================

Install  1 Package


Total download size: 39 k

Installed size: 94 k

Is this ok [y/d/N]: y

Downloading packages:

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  Installing : stress-1.0.4-16.el7.x86_64                                                                                          1/1 

  Verifying  : stress-1.0.4-16.el7.x86_64                                                                                          1/1 

Installed:

  stress.x86_64 0:1.0.4-16.el7 


Bonus info:

To know any information of installed package (such as, from which repo that package is installed;from which user;on which date;etc) , you can check in below path.

[root@server1 ~]# cd /var/lib/yum/yumdb/s/3e0e323a66f3c663e83f7bb670ca2c10219ddf6d-stress-1.0.4-16.el7-x86_64/

[root@server1 3e0e323a66f3c663e83f7bb670ca2c10219ddf6d-stress-1.0.4-16.el7-x86_64]# cat from_repo

shubhamrepo


=======================================================================

Thank you, check out more blogs for such information..!

 

For any queries,feel free to reach out me on shubhammore07007@gmail.com

Comments

  1. Excellent presentation, one question i have is, keeping the priority=1 is mandatory in repo ?

    ReplyDelete

Post a Comment

Popular posts from this blog

Nginx : Setting Up Nginx with Load Balancing

Nginx : Virtual hosting using Location directives

Terraform project with AWS to build infra within seconds! (Web Ec2 with eIP)