Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Extending software collections with additional packages

November 5, 2013
Doran Barton
Related topics:
Linux
Related products:
Red Hat Enterprise Linux

    Recent Red Hat Developer Blog articles have explained what Software Collections are, what they're good for, and how you can leverage them to easily enhance your development environment leveraging the latest and greatest versions of your favorite programming languages and relational database backends.

    But the software collection packages available for each language comprise only a subset of what is available — usually the core and some popular additions. Until that day when repositories have sprung up with all the additional SCL builds of libraries, modules, extensions to your language collection, you'll need to build those yourself.

    Fortunately, it's not very difficult.

    This article assumes you've built RPM packages before using the rpmbuild utility and any prior experience with the mock tool is also beneficial before diving in. If you want some more background, check out this article and this post in the Red Hat Customer Portal.

    Before building any SCL packages, there are a few packages you'll want to install with yum:

    sudo yum install scl-utils-build python-setuptools

    The scl-utils-build package adds, among some other things, several important RPM macros in /etc/rpm/macros.scl.

    Overview of the SCL build process

    Here are the steps required for building a package for a software collection.

    1. Obtain/create a source RPM or a spec file and source tarball
    2. Modify the spec file with SCL directives
    3. Build source and binary RPMs for a specific collection

    SCL-enabling a spec-file

    The Red Hat Software Collections documentation offers detailed information on what specifically needs to be added or modified in a spec file so that you may build a package for a software collection. It's usually easier to just use a handy script called spec2scl.

    The spec2scl script is installable with yum via the EPEL repository, but the developer has been actively updating this tool and, as a result, the version available in the EPEL repository is somewhat dated. It is advised that you use Python's easy_install utility to install the most up-to-date version of spec2scl:

    sudo easy_install spec2scl

    Building additional Perl CPAN modules for the perl516 collection

    As an example and an illustration, this article covers building additional packages for the perl516 collection.

    The perl516 collection contains the basic packages you will need to use Perl 5.16 on an EL6 system including modules like DBI, DBD::Pg, FCGI, and YAML, but leaves out a large number of popular CPAN modules. For example, Text::CSV_XS is commonly used for reading and writing comma-delimited text files and is not included in the perl516 collection, but that's okay because we can build it ourselves.

    We'll want to use the cpanspec tool to download CPAN modules and construct spec files, so install that.

    sudo yum install cpanspec

    Next, you can use the cpanspec tool to download a module's source tarball and construct a basic spec file:

    cpanspec Text::CSV_XS

    One notable behavior of cpanspec is it stores the source tarball it downloads and the spec file it builds in the current working directory. If you're working from your SPECS directory, you'll probably want to move the source tarball downloaded by cpanspec into the ../SOURCES directory.

    Next, run spec2scl to add the necessary SCL macros to the spec file.

    spec2scl -i -m perl-Text-CSV_XS.spec

    The -i option specifies that spec2scl should make in-place modifications to the spec file. The -m option specifies that the resulting RPM should depend on the SCL runtime package.

    You can then run rpmbuild with the spec file. Add -D 'scl perl516' to activate the conditional SCL macros in the spec file.

    rpmbuild -ba perl-Text-CSV_XS.spec -D 'scl perl516'

    This should build an installable RPM package.

    Using mock to build and maintain a repository of software collection packages

    The process described above is effective when you're building packages to be installed on the host you're building on and any dependent packages are already installed. Otherwise, you want to use a system that automatically resolves and installs dependencies as part of the build process. That's where mock comes in to play.

    mock builds packages in an isolated chroot environment and, because it's isolated from the rest of the system, can be used to build packages for other distributions and architectures. This makes it trivial (and very useful,) for example, to use mock to build packages for EL6 on a Fedora workstation.

    As you build packages for your software collection you will undoubtedly encounter packages which depend on others. By placing the dependent packages into a local repository, mock can install them in the chroot environment to build the package that has the dependencies.

    You will still want to use spec2scl to prepare a modified spec file for your package, but instead of using rpmbuild you will hand off package building to mock.

    First, install mock.

    sudo yum install mock

    Create a directory that will serve as your local repository for the packages you build.

    sudo mkdir -p /var/spool/local_yum_repos/perl516/{source,packages}

    Create a copy of a mock configuration file (these are found in /etc/mock) and extend with your base software repository information and local repository information.

    sudo cp /etc/mock/epel-6-x86_64.cfg /etc/mock/epel-6-x86_64-perl516-scl.cfg

    The lower portion of this file contains yum repository information, similar to what you'd fine in .repo files under /etc/yum.repos.d. For a mock environment that builds on top of the perl516 collection, add the following:

    [perl516]
    name=perl516
    baseurl=https://cdn.redhat.com/content/dist/rhel/server/6/x86_64/rhscl/1/os
    enabled=1
    [perl516_local]
    name=perl516_local
    baseurl=file:///var/spool/local_yum_repos/perl516
    enabled=1

    You'll also want to add some packages to always be installed in the chroot environment that are necessary for building SCL packages. To do this, modify the line near the top of the configuration file that defines the config_opts['chroot_setup_cmd'] option.

    config_opts['chroot_setup_cmd'] = 'install @buildsys-build scl-utils-build perl516-build perl516-perl-core'

    Run this mock command to initialize the mock root filesystem.

    mock -r epel-6-x86_64-perl516-scl --init

    Run this mock command to build a source RPM from a spec file.

    mock -r epel-6-x86_64-perl516-scl --buildsrpm --sources ~/rpm/SOURCES --spec ~/rpm/SPECS/perl-Text-CSV_XS.spec

    Copy the newly built source RPM to your local repository.

    cp /var/lib/mock/epel-6-x86_64-perl516-scl/result/perl516-perl-Text-CSV_XS-1.01-1.el6.src.rpm /var/spool/local_yum_repos/perl516/source

    Build binary RPM(s) from the source RPM.

    mock -r epel-6-x86_64-perl516-scl -D "scl perl516" /var/spool/local_yum_repos/perl516/source/perl516-perl-Text-CSV_XS-0.99-1.el6.src.rpm

    Copy the binary RPM(s) into the packages directory of your local repository.

    cp /var/lib/mock/epel-6-x86_64-perl516-scl/result/perl516-perl-Text-CSV_XS-1.01-1.el6.x86_64.rpm /var/spool/local_yum_repos/perl516/packages

    Regenerate the repository metadata.

    cd /var/spool/local_yum_repos/perl516
    createrepo .

    Now that this newly built package is in the directory created for the local package repository, any time mock builds a package that depends on it, it will be able to install it from the local repository to satisfy the dependency.

    Doran Barton is a senior developer at Bluehost. He is a Red Hat Certified Engineer and has worked with Linux since 1995 as a system administrator and as a software developer.

    Last updated: November 2, 2023

    Recent Posts

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.