9.2. RubyGems spec file conventions


A RubyGems spec file must meet the following conventions:

  • The file contains a definition of %{gem_name}, which is the name from the gem’s specification.
  • The source of the package must be the full URL to the released gem archive.
  • The version of the package must be the gem’s version.
  • The file contains the following BuildRequires: directive:

    BuildRequires: rubygems-devel

    The rubygems-devel package contains macros needed for a build.

  • The file does not contain any additional rubygem(foo) Requires or Provides directives because these directives are autogenerated from the gem metadata.

9.2.1. RubyGems spec file example

The following is the RubyGems-specific part of an example spec file for building gems. The remaining part of the spec file follows the generic guidelines.

A RubyGems-specific part of an example spec file

%prep
%setup -q -n  %{gem_name}-%{version}

# Modify the gemspec if necessary
# Also apply patches to code if necessary
%patch 0 -p1

%build
# Create the gem as gem install only works on a gem file
gem build ../%{gem_name}-%{version}.gemspec

# %%gem_install compiles any C extensions and installs the gem into ./%%gem_dir
# by default, so that we can move it into the buildroot in %%install
%gem_install

%install
mkdir -p %{buildroot}%{gem_dir}
cp -a ./%{gem_dir}/* %{buildroot}%{gem_dir}/

# If there were programs installed:
mkdir -p %{buildroot}%{_bindir}
cp -a ./%{_bindir}/* %{buildroot}%{_bindir}

# If there are C extensions, copy them to the extdir.
mkdir -p %{buildroot}%{gem_extdir_mri}
cp -a .%{gem_extdir_mri}/{gem.build_complete,*.so} %{buildroot}%{gem_extdir_mri}/

9.2.2. RubyGems spec file directives

The following are the specifics of particular items in the RubyGems-specific part of the spec file.

Expand
表 9.1. RubyGems' spec directives specifics
DirectiveRubyGems specifics

%prep

RPM can directly unpack gem archives. The %setup -n %{gem_name}-%{version} macro provides the directory into which the gem is unpacked. At the same directory level, the %{gem_name}-%{version}.gemspec file is automatically created. You can use this file to perform the following actions:

  • Modify the .gemspec file
  • Apply patches to the code.

%build

This section includes commands for building the software into machine code. The %gem_install macro operates only on gem archives. Therefore, you must first re-create the archive by using the gem build ../%{gem_name}-%{version}.gemspec command. The recreated gem file is then used by %gem_install to build and install the gem code into the default ./%{gem_dir} temporary directory. Before being installed, the built sources are placed into a temporary directory that is created automatically.

%install

The installation is performed into the %{buildroot} hierarchy. You can create the necessary directories and then copy the installed code from the temporary directories into the %{buildroot} hierarchy. If the gem creates shared objects, they are moved into the architecture-specific %{gem_extdir_mri} path.

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat
返回顶部