Skip to main content
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 Red Hat 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

    • Red Hat OpenShift AI
    • 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.

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

    • 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.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

How to package Go applications in RHEL 10

December 10, 2024
Alejandro Sáez Morollón
Related topics:
ContainersDeveloper productivityDeveloper toolsDevOpsGoLinux
Related products:
Red Hat Enterprise Linux

    Until now, packaging Go applications for Red Hat Enterprise Linux (RHEL) was very different from packaging them for Fedora. Fedora has plenty of tools that make the process as easy and quick as possible. And now, with the release of RHEL 10 beta, the packaging differences between Fedora, CentOS Stream and RHEL are smaller than ever before. We can also work from a Fedora machine without complex setups.

    Let's explore how similar the process is now and how you can package a sample Go application faster than ever in RHEL 10.

    Packaging Go applications in Red Hat Enterprise Linux 10

    For the sake of this article, I made a sample application that basically prints a little of information about the system. You can find the code in this repository. But the code is as simple as it gets:

    package main
    import (
        "fmt"
        "os"
        "runtime"
    )
    func getRelease() error {
        content, err := os.ReadFile("/etc/redhat-release")
        if err != nil {
            if os.IsNotExist(err) {
                return fmt.Errorf("file not found")
            }
            return fmt.Errorf("failed to read file: %w", err)
        }
        fmt.Printf("OS: %s", string(content))
        return nil
    }
    func main() {
        getRelease()
        fmt.Printf("Arch: %s\n", runtime.GOARCH)
        fmt.Printf("Go version: %s\n", runtime.Version())
    }

    The idea behind the workflow for packaging a Go project has not changed, and you can see how I discussed this a few years ago. However, the process became cumbersome as the applications became more complex. The vast majority of the steps can now be leveraged to more modern, up-to-date tools. The majority of RPM packagers operate on Fedora desktops, and so do we. If you don't have a Fedora setup at hand or don't want to mess with your setup directly, we'll use a container.

    $ podman pull registry.fedoraproject.org/fedora-toolbox:41
    Trying to pull registry.fedoraproject.org/fedora-toolbox:41...
    Getting image source signatures
    Copying blob cabdb1918cf1 skipped: already exists  
    Copying config 8a11b6229e done   | 
    Writing manifest to image destination
    8a11b6229efe85b59df4b7ae2fd7c27dc1ac9b553ddcdecf932e0256c7c2e710
    $ podman run -it registry.fedoraproject.org/fedora-toolbox:41 /bin/bash
    [root@18af08a1e3ce /]# 

    If you have Toolbx installed, the process couldn't be easier:

    $ toolbox create 
    Image required to create Toolbx container.
    Download registry.fedoraproject.org/fedora-toolbox:41 (375.4MB)? [y/N]: y
    Created container: fedora-toolbox-41
    Enter with: toolbox enter
    $ toolbox enter
    [fedora-toolbox-41]$

    Regardless of your choice, you should now have a Fedora 41 environment, where we can install all the necessary components.

    [fedora-toolbox-41]$ sudo dnf install golang go-rpm-macros go2rpm fedpkg centpkg "@rpm-development-tools" -y

    Before, we had to create the specfile file manually and adjust several steps to meet the needs of the application we were packaging. However, we can now use go2rpm to generate the specfile file automatically. Usually, there aren't many changes required.

    If you look at the Go sample repository, you'll see I created a release. This is intentional to represent a real upstream project and to make life easier for go2rpm, but you can always specify a commit or a tag in case you want a specific release:

    [fedora-toolbox-41]$ go2rpm github.com/alexsaezm/rhd_blog2024
    # OR
    [fedora-toolbox-41]$ go2rpm github.com/alexsaezm/rhd_blog2024 --commit 3da750

    Both commands will create a specfile in the current path. After this, we can use spectool and centpkg to build our package. This tool requires us to work with a Git repository. If you aren't already working on a Git repository, create one before you tackle any of the following steps:

    [fedora-toolbox-41]$ go2rpm github.com/alexsaezm/rhd_blog2024
    [fedora-toolbox-41]$ spectool -g golang-github-alexsaezm-rhd-blog2024.spec
    [fedora-toolbox-41]$ centpkg --release c10s mockbuild

    This will create a folder that starts with results_, inside which you will find the resulting RPM packages. These packages can now be installed on your CentOS Stream 10 or RHEL 10 machine.

    Furthermore, we can build it for Fedora without any modifications:

    [fedora-toolbox-41]$ fedpkg --release rawhide mockbuild

    This also simplifies the process of creating an RPM during a CI pipeline. For example, we could add the previous steps to a Containerfile to complete the process with a small tweak. Instead of using mockbuild which uses a container to perform the build, we can now use local:

    FROM registry.fedoraproject.org/fedora-minimal:latest
    RUN dnf install -y \
       golang \
       go-rpm-macros \
       centpkg \
       "@rpm-development-tools" && \
       dnf clean all
    WORKDIR /build
    COPY . .
    RUN centpkg --release c10s local

    Final thoughts

    This is, of course, a demo. The next step in a normal packaging workflow would be to put the RPM on a repository so that all machines with it configured would have the update.

    Personally, I am very excited about the packaging for RHEL 10 and Go. Some people used to complain that it was challenging to make a Go package work in Fedora and RHEL at the same time. Now that gap is even smaller than ever before.

    Related Posts

    • Build your own RPM package with a sample Go program

    • Using Delve to debug Go programs on Red Hat Enterprise Linux

    • Register allocation in the Go compiler

    • Implementing OpenSSL-backed Go cryptographic algorithms

    • How to add debug support for Go stripped binaries

    • Python performance optimizations with RHEL 9.5

    Recent Posts

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    • Control multicluster costs with right-sizing in Red Hat Advanced Cluster Management 5

    • Lightbits is now certified for Red Hat OpenStack Services on OpenShift

    What’s up next?

    This cheat sheet covers the basics of installing .NET on Red Hat Enterprise Linux (RHEL), how to get a simple program running, and how to run a program in a Linux container.

    Get the cheat sheet
    Red Hat Developers logo

    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
    Ask AI