Use gem2rpm to generate a spec file

Create an RPM spec file for building gems by using the gem2rpm utility.

Create an RPM spec file for a Ruby gem

Generate an RPM spec file for a RubyGems package by using the gem2rpm utility.

Before you begin

  • You have the gem2rpm utility installed on your system:
    $ gem install gem2rpm

Procedure

  1. Download a gem in its latest version and generate the RPM spec file for this gem:
    $ gem2rpm --fetch <gem_name> > <gem_name>.spec
  2. Edit the generated spec file to add the missing information, for example, a license and a changelog.

Use custom gem2rpm templates to generate a spec file

gem2rpm templates are standard Embedded Ruby (ERB) files that RPM spec files can be generated from. Edit the template from which the RPM spec file is generated instead of editing the generated spec file.

Before you begin

  • You have the gem2rpm utility installed on your system:
    $ gem install gem2rpm

Procedure

  1. Display all gem2rpm built-in templates:
    $ gem2rpm --templates
  2. Select one of the built-in templates and save it as a custom template:
    $ gem2rpm -t <template> -T > rubygem-<gem_name>.spec.template

    Note that for RHEL 10 Beta, the fedora-27-rawhide template is recommended.

  3. Edit the template as needed. For more information, see gem2rpm template variables.
  4. Generate the spec file by using the edited template:
    $ gem2rpm -t rubygem-<gem_name>.spec.template <gem_name>-<latest_version>.gem > <gem_name>-GEM.spec

gem2rpm template variables

Review the following variables included in the gem2rpm template for RPM spec file generation.

Table 1. Variables in the gem2rpm template
Variable Explanation

package

The Gem::Package variable for the gem.

spec

The Gem::Specification variable for the gem (the same as format.spec).

config

The Gem2Rpm::Configuration variable that can redefine default macros or rules used in spec template helpers.

runtime_dependencies

The Gem2Rpm::RpmDependencyList variable that provides a list of package runtime dependencies.

development_dependencies

The Gem2Rpm::RpmDependencyList variable that provides a list of package development dependencies.

tests

The Gem2Rpm::TestSuite variable that provides a list of test frameworks allowing their execution.

files

The Gem2Rpm::RpmFileList variable that provides an unfiltered list of files in a package.

main_files

The Gem2Rpm::RpmFileList variable that provides a list of files suitable for the main package.

doc_files

The Gem2Rpm::RpmFileList variable that provides a list of files suitable for the -doc subpackage.