Operations 5 min read

Quickly Package Go Binaries into RPMs with go-bin-rpm and Makefile

This guide walks you through installing the required build tools, configuring go-bin-rpm with a concise rpm.json file, generating RPM packages, and automating the process with a Makefile for seamless Go binary deployment on RPM‑based systems.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Quickly Package Go Binaries into RPMs with go-bin-rpm and Makefile

1. Environment Preparation

Install the necessary rpmbuild dependencies regardless of the programming language:

yum install -y gcc make rpm-build redhat-rpm-config

Install the open‑source tool go-bin-rpm using the following one‑liner:

wget -O - https://raw.githubusercontent.com/mh-cbon/latest/master/bintray.sh \
| GH=mh-cbon/go-bin-rpm sh -xe

Verify the installation:

$ go-bin-rpm --version
go-bin-rpm version 1.0.0

2. Configuration File

The default configuration file for go-bin-rpm is rpm.json. A minimal example looks like this:

{
  "name": "you-service-name",
  "version": "0.0.1",
  "release": "20221110",
  "arch": "x86_64",
  "summary": "",
  "description": "",
  "license": "iswbm.com",
  "url": "https://gtihub.com/iswbm/!name!",
  "files": [
    {
      "from": "./bin/!name!",
      "to": "/usr/local/!name!/",
      "base": "",
      "type": ""
    },
    {
      "from": "./!name!.service",
      "to": "/usr/lib/systemd/system/",
      "base": "",
      "type": ""
    }
  ]
}

If the installed package runs as a service, the files array should contain the binary, the service file, and any configuration files needed.

Example .service template:

[Unit]
Description=
After=syslog.target network.target

[Service]
Environment=key=value
Type=simple
NotifyAccess=all
TimeoutStartSec=0
Restart=always
User=root
ExecStart=/usr/local/xxxx/bin/xxxx

[Install]
WantedBy=multi-user.target

Generate the RPM with:

# Replace VERSION and RELEASE accordingly
go-bin-rpm generate -o rpms/xxxx-$(VERSION)-$(RELEASE).rpm

For multiple binaries or platforms, prepare separate rpm.json files and specify them with -f rpm.json during generation.

3. Using a Makefile

To simplify the workflow, create a Makefile like the following:

VERSION = 1.0.0
RELEASE = $(shell date +"%Y%m%d")

.PHONY: build-go
build-go:
	go build -o ./bin/hello .

.PHONY: build
build: build-go
	sed -i "s/VERSION/$(VERSION)/g" rpm.json
	sed -i "s/RELEASE/$(RELEASE)/g" rpm.json
	mkdir -p rpms
	go-bin-rpm generate -o rpms/hellp-$(VERSION)-$(RELEASE).rpm

Running make build will compile the Go binary, inject the version and release into rpm.json, create the output directory, and produce the RPM in a single step.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

OperationspackagingMakefilego-bin-rpm
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.