If your Red Hat server is not connected to the official RHN repositories, you will need to configure your own private repository which you can later use to install packages. The procedure of creating a Red Hat Linux repository is quite a simple task. In this article, we will show you how to create a local file Red Hat repository as well as a remote HTTP repository.

In this tutorial you will learn:
  • How to use official Red Hat DVD as repository
  • How to create a local file Red Hat repository
  • How to create a remote HTTP Red Hat repository
Using a custom Red Hat repository - in this case from a Red Hat DVD
Using a custom Red Hat repository - in this case from a Red Hat DVD
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Red Hat
Software createrepo
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

Using official Red Hat DVD as repository

 

SUBSCRIBE TO NEWSLETTER
Subscribe to our NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.


After default installation and without registering your server to official RHN repositories your are left without any chance to install new packages from Red Hat repository as your repository list will show 0 entries:

# dnf repolist
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
repolist: 0

At this point the easiest thing to do is to attach your Red Hat installation DVD as a local repository. To do that, first make sure that your RHEL DVD is mounted:

# mount | grep iso9660
/dev/sr0 on /media/RHEL_6.4 x86_64 Disc 1 type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=500,gid=500,iocharset=utf8,mode=0400,dmode=0500)

The directory which most interests us at the moment is /media/RHEL_6.4 x86_64 Disc 1/repodata as this is the directory which contains information about all packages found on this particular DVD disc.

Next we need to define our new repository pointing to /media/RHEL_6.4 x86_64 Disc 1/ by creating a repository entry in /etc/yum.repos.d/. Create a new file called: /etc/yum.repos.d/RHEL_6.4_Disc.repo using vi editor and insert the following text:

[RHEL_6.4_Disc]
name=RHEL_6.4_x86_64_Disc
baseurl="file:///media/RHEL_6.4 x86_64 Disc 1/"
gpgcheck=0

Once file was created your local Red Hat DVD repository should be ready to use:

# dnf repolist
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
repo id                                                     repo name                                                           status
RHEL_6.4_Disc                                               RHEL_6.4_x86_64_Disc                                                3,648
repolist: 3,648

Creating a local file Red Hat repository

 


Normally, having a Red Hat DVD repository will be enough to get you started; however, the only disadvantage is that you are not able to alter your repository in any way and thus not able to insert new/updated packages into it. To resolve this issue, we can create a local file repository sitting somewhere on the filesystem. To aid us with this plan we will use a createrepo utility.

  1. Start by installing the createrepo on your system if it isn't already installed.
    # dnf install createrepo
    
  2. At this stage we are ready to create our own Red Hat local file repository. Create a new directory called /rhel_repo:
    # mkdir /rhel_repo
    
  3. Next, copy all packages from your mounted RHEL DVD to your new directory:
    # cp /media/RHEL_6.4\ x86_64\ Disc\ 1/Packages/* /rhel_repo/
    
  4. When copy is finished execute createrepo command with a single argument which is your new local repository directory name:
    # createrepo /rhel_repo/
    Spawning worker 0 with 3648 pkgs
    Workers Finished
    Gathering worker results
    
    Saving Primary metadata
    Saving file lists metadata
    Saving other metadata
    Generating sqlite DBs
    Sqlite DBs complete
    
  5. As the last step, we will create a new yum repository entry by editing this file:
    # vi /etc/yum.repos.d/rhel_repo.repo
    
    And inserting this text:
    [rhel_repo]
    name=RHEL_6.4_x86_64_Local
    baseurl="file:///rhel_repo/"
    gpgcheck=0
    
  6.  


  7. Your new repository should now be accessible:
    # dnf repolist
    Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    rhel_repo                                                                                                      | 2.9 kB     00:00 ... 
    rhel_repo/primary_db                                                                                           | 367 kB     00:00 ... 
    repo id                                                     repo name                                                           status
    RHEL_6.4_Disc                                               RHEL_6.4_x86_64_Disc                                                3,648
    rhel_repo                                                   RHEL_6.4_x86_64_Local                                                 3,648
    

Creating a remote HTTP Red Hat repository

If you have multiple Red Hat servers, you may want to create a single Red Hat repository accessible by all other servers on the network. For this you will need Apache web server. If you need help getting Apache set up, check our guide about installing Apache on RHEL.

In order to make your new repository accessible via http configure your Apache with /rhel_repo/ directory created in previous section as document root directory or simply copy entire directory to: /var/www/html/ (default document root).

  1. First, create a new yum repository entry on your client system by creating a new repo configuration file:
    # vi /etc/yum.repos.d/rhel_http_repo.repo
    
    with the following content, where the host is an IP address or hostname of your Red Hat repository server:
    [rhel_repo_http]
    name=RHEL_6.4_x86_64_HTTP
    baseurl="http://myhost/rhel_repo/"
    gpgcheck=0
    
  2. Confirm the correctness of your new repository by running the dnf repolist command.
    # dnf repolist
    Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
    This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
    repo id                                                      repo name                                                          status
    rhel_repo_http                                               RHEL_6.4_x86_64_HTTP                                               3,648
    repolist: 3,648
    

Closing Thoughts

Creating your own package repository gives you more options on how to manage packages on your Red Hat system even without paid RHN subscription. When using a remote HTTP Red Hat repository you may also want to configure GPGCHECK as part of your repository to make sure that no packages had been tampered to prior their installation.

FIND LATEST LINUX JOBS on LinuxCareers.com
Submit your RESUME, create a JOB ALERT.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.