RPM Builder
RPM Builder is a Node.js library designed to create Red Hat Package Manager (RPM) packages programmatically. It wraps the underlying `rpmbuild` system utility, abstracting away the complexities of direct command-line execution and spec file generation. The package allows developers to define package metadata, specify files, handle glob patterns, and exclude files using a simple JavaScript API. The current stable version is 1.2.1, released over six years ago, and the package is effectively abandoned, meaning no further updates, feature enhancements, or security patches are expected. Its primary differentiator is providing a native Node.js interface for RPM creation, which can be integrated into CI/CD pipelines for projects requiring RPM distribution artifacts. It simplifies the packaging process compared to manually creating `.spec` files and executing `rpmbuild` commands.
Common errors
-
Error: spawn rpmbuild ENOENT
cause The `rpmbuild` command-line utility, which `rpm-builder` shells out to, is not installed on the system or is not found in the system's PATH.fixInstall `rpmbuild` on your operating system. For Fedora/CentOS, run `sudo yum install rpmdevtools` or `sudo dnf install rpmdevtools`. For Ubuntu/Debian, run `sudo apt-get install rpm`. On macOS, install via Homebrew (`brew install rpm`) and ensure it's in your PATH. -
Files are missing in the resulting RPM package, or they appear in the wrong directory structure.
cause Incorrect `src`, `dest`, or `cwd` path configurations within the `files` array. Relative paths are resolved against `process.cwd()` unless `cwd` is specified per file.fixDouble-check all paths in your `files` array. Ensure `src` paths correctly point to existing files/globs relative to where your Node.js script is executed or specify a `cwd` for each file entry. Verify `dest` paths reflect the desired target location *within the RPM package*. -
TypeError: buildRpm is not a function
cause Attempting to use `rpm-builder` with ESM `import` syntax (`import buildRpm from 'rpm-builder';`) in an environment that does not transpile CommonJS modules, or when assuming it exports a default function for ESM.fixUse the CommonJS `require` syntax: `const buildRpm = require('rpm-builder');` The package is not designed for native ESM environments.
Warnings
- breaking The `rpm-builder` package is effectively abandoned, with no updates in over six years. This means there will be no future security fixes, bug patches, or feature enhancements. Use in production environments without careful security review and mitigation strategies is not recommended.
- gotcha This library critically depends on the `rpmbuild` utility being installed and available in the system's PATH. If `rpmbuild` is not found, the build process will fail with an 'ENOENT' error (No such file or directory) during the `spawn` call.
- gotcha Paths specified in `files` objects (`src`, `dest`) and `excludeFiles` are relative to the *process's current working directory* (`process.cwd()`) by default, unless a `cwd` property is explicitly set on a specific file entry. Misunderstanding this can lead to files not being included or being placed incorrectly in the RPM.
- gotcha The `tempDir` option defaults to a dynamically generated directory and is automatically cleaned up after the RPM build completes (unless `keepTemp` is `true`). If the build fails or you need to inspect the intermediate build artifacts, the temporary directory will be gone.
Install
-
npm install rpm-builder -
yarn add rpm-builder -
pnpm add rpm-builder
Imports
- buildRpm
import buildRpm from 'rpm-builder';
const buildRpm = require('rpm-builder'); - buildRpm (callback API)
require('rpm-builder')(options, callback);
Quickstart
const buildRpm = require('rpm-builder');
const path = require('path');
const fs = require('fs');
// Create some dummy files for the RPM
const tempDir = path.join(__dirname, 'temp_app_files');
fs.mkdirSync(tempDir, { recursive: true });
fs.writeFileSync(path.join(tempDir, 'app.js'), 'console.log("Hello RPM!");');
fs.writeFileSync(path.join(tempDir, 'config.json'), '{ "port": 3000 }');
const options = {
name: 'my-node-application',
version: '1.0.0',
release: '1',
summary: 'A simple Node.js application packaged as an RPM',
description: 'This RPM contains a basic Node.js script and a configuration file.',
group: 'Development/Tools',
license: 'MIT',
vendor: 'MyCompany',
buildArch: 'noarch',
files: [
{ src: path.join(tempDir, 'app.js'), dest: '/usr/local/bin/my-app/app.js' },
{ src: path.join(tempDir, 'config.json'), dest: '/etc/my-app/config.json' }
],
// Optional: Set a temporary directory, will be cleaned up by default
tempDir: path.join(__dirname, 'rpm_build_tmp'),
// Optional: Keep the temporary directory for inspection after build
keepTemp: false
};
buildRpm(options, function(err, rpmPath) {
// Clean up dummy files after attempting RPM build
fs.rmSync(tempDir, { recursive: true, force: true });
if (options.tempDir && !options.keepTemp) {
fs.rmSync(options.tempDir, { recursive: true, force: true });
}
if (err) {
console.error('Failed to build RPM:', err);
return;
}
console.log('Successfully built RPM:', rpmPath);
// Example: mv ' + rpmPath + ' /path/to/my/rpms/new-package.rpm
});