Setup Local Yum Repository On CentOS 7
Setup Local Yum Repository On CentOS 7
com/setup-local-yum-repository-centos-7/
unixmen.com
This tutorial describes how to setup a local Yum repository on CentOS 7 system. Also, the same steps should work on
RHEL and Scientific Linux 7 systems too.
If you have to install software, security updates and fixes often in multiple systems in your local network, then having a local
repository is an efficient way. Because all required packages are downloaded over the fast LAN connection from your local
server, so that it will save your Internet bandwidth and reduces your annual cost of Internet.
In this tutorial, I use two systems as described below:
Yum Server OS : CentOS 7 (Minimal Install)
Yum Server IP Address : 192.168.1.101
Client OS : CentOS 7 (Minimal Install)
Client IP Address : 192.168.1.102
Prerequisites
First, mount your CentOS 7 installation DVD. For example, let us mount the installation media on /mnt directory.
mount /dev/cdrom /mnt/
Now the CentOS installation DVD is mounted under /mnt directory. Next install vsftpd package and let the packages
available over FTP to your local clients.
To do that change to /mnt/Packages directory:
cd /mnt/Packages/
Now install vsftpd package:
It’s time to build our local repository. Create a storage directory to store all packages from CentOS DVD’s.
As I noted above, we are going to use a FTP server to serve all packages to client systems. So let us create a storage
location in our FTP server pub directory.
mkdir /var/ftp/pub/localrepo
Now, copy all the files from CentOS DVD(s) i.e from /mnt/Packages/ directory to the “localrepo” directory:
cp -ar /mnt/Packages/*.* /var/ftp/pub/localrepo/
Again, mount the CentOS installation DVD 2 and copy all the files to /var/ftp/pub/localrepo directory.
Once you copied all the files, create a repository file called “localrepo.repo” under /etc/yum.repos.d/ directory and add the
following lines into the file. You can name this file as per your liking:
vi /etc/yum.repos.d/localrepo.repo
Add the following lines:
[localrepo]
name=Unixmen Repository
baseurl=file:///var/ftp/pub/localrepo
gpgcheck=0
enabled=1
Note: Use three slashes(///) in the baseurl.
Now, start building local repository:
createrepo -v /var/ftp/pub/localrepo/
Now the repository building process will start.
Sample Output:
2.4.6-17.el7.centos.1.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-17.el7.centos.1.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-
2.4.6-17.el7.centos.1.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-
2.4.6-17.el7.centos.1.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-17.el7.centos.1 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================
Package Arch
Version Repository Size
=============================================================================================================
Installing:
httpd x86_64
2.4.6-17.el7.centos.1 localrepo 2.7 M
Installing for dependencies:
apr x86_64
1.4.8-3.el7 localrepo 103 k
apr-util x86_64
1.5.2-6.el7 localrepo 92 k
httpd-tools x86_64
2.4.6-17.el7.centos.1 localrepo 77 k
mailcap noarch
2.1.41-2.el7 localrepo 31 k
Transaction Summary
=============================================================================================================
Install 1 Package (+4 Dependent packages)
Now, go to your client systems. Create a new repository file as shown above under /etc/yum.repos.d/ directory.
vi /etc/yum.repos.d/localrepo.repo
and add the following contents:
[localrepo]
name=Unixmen Repository
baseurl=ftp://192.168.1.101/pub/localrepo
gpgcheck=0
enabled=1
Note: Use double slashes in the baseurl and 192.168.1.101 is yum server IP Address.
Now, list out the repositories using the following command:
yum repolist
Clean the Yum cache and update the repository lists:
yum clean all
yum update
Disable or rename the existing repositories if you only want to install packages from the server local repository itself.
Alternatively, you can install packages from the local repository by mentioning the repository as shown below.
yum install --disablerepo="*" --enablerepo="localrepo" httpd
Sample Output:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-17.el7.centos.1 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-17.el7.centos.1 for package: httpd-
2.4.6-17.el7.centos.1.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-17.el7.centos.1.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-
2.4.6-17.el7.centos.1.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-
2.4.6-17.el7.centos.1.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-17.el7.centos.1 will be installed
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
httpd x86_64 2.4.6-17.el7.centos.1 localrepo 2.7 M
Installing for dependencies:
apr x86_64 1.4.8-3.el7 localrepo 103 k
apr-util x86_64 1.5.2-6.el7 localrepo 92 k
httpd-tools x86_64 2.4.6-17.el7.centos.1 localrepo 77 k
mailcap noarch 2.1.41-2.el7 localrepo 31 k
Transaction Summary
================================================================================
Install 1 Package (+4 Dependent packages)
Installed:
httpd.x86_64 0:2.4.6-17.el7.centos.1
Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-17.el7.centos.1 mailcap.noarch 0:2.1.41-2.el7
Complete!
That’s it. Now, you will be able to install softwares from your server local repository.
Cheers!