9.4. Using gem2rpm to generate a spec file


You can use the gem2rpm utility to create an RPM spec file.

9.4.1. Creating an RPM spec file for a Ruby gem

You can generate an RPM spec file for a RubyGems package by using the gem2rpm utility.

Prerequisites

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

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

Prerequisites

  • 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

9.4.3. gem2rpm template variables

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

Expand
表 9.3. Variables in the gem2rpm template
VariableExplanation

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.

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部