Create a Local Repository in Linux

The steps to create a local repository from CD/DVD are listed below:

  • Open the VirtualBox Manager and click on Start.
  • Once started, right-click and select the Open Terminal option.
  • Become a root, by running the command:
    su -​
  • Select Devices from the Top Menu. Then choose the option Optical Device. Select the Choose disk image.
  • Browse and pick the CentOS Image file.
  • A pop-up comes up at the upper right of the screen.
  • Verify if the disk is attached by running the command:
    df -h​

    The output shall be:

  • Create a directory local repo in the location /, by running the commands:
    cd /
    mkdir localrepo​
  • Move to the directory /run/media/user/Cent0S 7 X86_64 with the command:
    cd /run/media/username/CentOS\ 7\ x86_64/​
CentOS 7 x86_64 has spaces. Linux does not accept spaces in directory names. Hence we written the directory name as /run/media/username/CentOS\ 7\ x86_64/​.
  • To get the list of all files under the Cent0S 7 X86_64 direction, run the command:
    ls -ltr​
  • Move to the Packages directory where all the packages reside, with the command:
    cd Packages​/
  • To count the number of packages within that disk, run the command:
    ls -ltr | wc -l​
  • Copy all the contents of the /run/media/username/CentOS 7 x86_64/​ to localrepo directory with the command:
    cp  -rv /run/media/username/CentOS\ 7\ x86_64/​Packages/* /localrepo/​
  • Once all the files are copied, move to the /etc/yum.repos.d/ directory with the command:
    cd /etc/yum.repos.d/​
  • Delete the existing repos from that directory with the command:
    rm -rf /etc/yum.repos.d/*​
  • Create a new repo in this directory with the command:
    vi local.repo​
  • Add the parameters in the vi editor in the insert mode:
  • Create the repo with the command:
    createrepo /localrepo/​

The output shall be : linux-localrepo7

  • Clear the cache from the old repo, with the command:
    yum clean all​
  • To get the current list of the repo, run the command:
    yum repolist all​
  • Now install a repo for example tomcat, with the command:
    yum install tomcat​

All the packages should get installed from the local repo.

About Author :

Myself Debomita Bhattacharjee, an IT employee with 6+ years of experience in Software industry. My area of interest is Automation testing and Front End Development.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions