How to create a local repository for updates

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6
  • Red Hat Enterprise Linux 7

Issue

  • yum can be used to update or install packages for Red Hat Enterprise Linux 5, 6 and 7 from a customized repository.
  • Which packages should I install to have createrepo and reposync commands available?
  • How do I update the server/system through a local repo?
  • How do I create a local repository for updates?
  • How do I set up a local repository for Red Hat Enterprise Linux?
  • Some packages need to be added to a local repository. How can this be done?

Resolution

To use yum to install or update packages from an ISO file, a repository will need to be created:

  1. Create the directory that will hold the repository:

    # mkdir -p /var/www/html/repo    
    
  2. There are two ways to create a repository:

    • Move the rpms for the repository into the directory, then run createrepo against that:

      # cp *.rpm /var/www/html/repo
      # createrepo /var/www/html/repo
      
    • Or, reposync against an existing repository:

      # reposync -p /var/www/html/repo -r <REPOID> -l
      # createrepo /var/www/html/repo    
      
  3. Start apache, and confirm access to the repodata files:

    # wget http://localhost/repo/repomd.xml
    # wget http://myfqdn.com/repo/repomd.xml    
    
  4. If both of the above commands were successful, configure a httpd based yum repository, which can be used by this server and another server.
  5. If packages need to be added to the repo at a later date, add the new RPMs to the directory and run this command:

    # createrepo --update  /var/www/html/repo  
    
  6. Before seeing the updates on yum clients you may need to:

    # rm -rf /var/cache/yum/*
    # yum clean all
    

NOTE:

  • When synchronizing repositories from Red Hat Satellite or Red Hat Subscription Management itself, only repositories that the server is subscribed to can be synchronized. The following command shows repositories accessible through a chosen plugin. YUMPLUGIN variable can be replaced with a plugin name:

    # YUMPLUGIN=rhnplugin; cd /etc/yum/pluginconf.d/ && echo *.conf|sed "s/$YUMPLUGIN.conf//"|sed 's/\([0-9a-zA-Z\-]*\).conf/--disableplugin=\1/g'|xargs yum repolist && cd - >/dev/null
    
  • In order to have the commands createrepo and repo-sync available, install the packages createrepo and yum-utils respectively, which are not available in the default RHEL setup:

    # yum install -y createrepo yum-utils
    

Diagnostic Steps

When troubleshooting issues like this, remember that apache must be able to access these files. This may include permissions, ACLs, and SELinux contexts (if enabled).

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments