RubyGems Navigation menu

The Specification class contains the information for a gem. Typically defined in a .gemspec file or a Rakefile, and looks like this: do |s|        = 'example'
  s.version     = '0.1.0'
  s.licenses    = ['MIT']
  s.summary     = "This is an example!"
  s.description = "Much longer explanation of the example!"
  s.authors     = ["Ruby Coder"]       = ''
  s.files       = ["lib/example.rb"]
  s.homepage    = ''
  s.metadata    = { "source_code_uri" => "" }

Starting in RubyGems 2.0, a Specification can hold arbitrary metadata. See metadata for restrictions on the format and size of metadata items you may add to a specification.

Required gemspec attributes

Read-only attributes

Optional gemspec attributes

Required gemspec attributes


A list of authors for this gem.

Alternatively, a single author can be specified by assigning a string to


spec.authors = ['John Jones', 'Mary Smith']


Files included in this gem. You cannot append to this accessor, you must assign to it.

Only add files you can require to this list, not directories, etc.

Directories are automatically stripped from this list when building a gem, other non-files cause an error.


require 'rake'
spec.files = FileList['lib/**/*.rb',

# or without Rake...
spec.files = Dir['lib/**/*.rb'] + Dir['bin/*']
spec.files += Dir['[A-Z]*']
spec.files.reject! { |fn| fn.include? "CVS" }


This gem’s name.

Usage: = 'rake'


A short summary of this gem’s description. Displayed in gem list -d.

The description should be more detailed than the summary.


spec.summary = "This is a small summary of my gem"


This gem’s version.

The version string can contain numbers and periods, such as 1.0.0. A gem is a ‘prerelease’ gem if the version has a letter in it, such as 1.0.0.pre.


spec.version = '0.4.1'

Recommended gemspec attributes


A long description of this gem

The description should be more detailed than the summary but not excessively long. A few paragraphs is a recommended length with no examples or formatting.


spec.description = <<~EOF
  Rake is a Make-like program implemented in Ruby. Tasks and
  dependencies are specified in standard Ruby syntax.


A contact email address (or addresses) for this gem

Usage: = '' = ['', '']


The URL of this gem’s home page


spec.homepage = ''


The license for this gem.

The license must be no more than 64 characters.

This should just be the name of your license. The full text of the license should be inside of the gem (at the top level) when you build it.

The simplest way is to specify the standard SPDX ID for the license. Ideally, you should pick one that is OSI (Open Source Initiative) approved.

The most commonly used OSI-approved licenses are MIT and Apache-2.0. GitHub also provides a license picker at

You can also use a custom license file along with your gemspec and specify a LicenseRef-<idstring>, where idstring is the name of the file containing the license text.

You should specify a license for your gem so that people know how they are permitted to use it and any restrictions you’re placing on it. Not specifying a license means all rights are reserved; others have no right to use the code for any purpose.

You can set multiple licenses with licenses=


spec.license = 'MIT'


The license(s) for the library.

Each license must be a short name, no more than 64 characters.

This should just be the name of your license. The full text of the license should be inside of the gem when you build it.

See license= for more discussion


spec.licenses = ['MIT', 'GPL-2.0']


The metadata holds extra data for this gem that may be useful to other consumers and is settable by gem authors.

Metadata items have the following restrictions:

  • The metadata must be a Hash object

  • All keys and values must be Strings

  • Keys can be a maximum of 128 bytes and values can be a maximum of 1024 bytes

  • All strings must be UTF-8, no binary data is allowed

You can use metadata to specify links to your gem’s homepage, codebase, documentation, wiki, mailing list, issue tracker and changelog.

s.metadata = {
  "bug_tracker_uri"   => "",
  "changelog_uri"     => "",
  "documentation_uri" => "",
  "homepage_uri"      => "",
  "mailing_list_uri"  => "",
  "source_code_uri"   => "",
  "wiki_uri"          => ""
  "funding_uri"       => ""

These links will be used on your gem’s page on and must pass validation against following regex.



The version of Ruby required by this gem


spec.required_ruby_version = '>= 2.7.0'

Read-only attributes


The path where this gem installs its extensions.


The version of RubyGems used to create this gem.

Optional gemspec attributes

add_dependency(gem, *requirements)

Adds a runtime dependency named gem with requirements to this gem.


spec.add_dependency 'example', '~> 1.1', '>= 1.1.4'

Also known as: add_runtime_dependency

add_development_dependency(gem, *requirements)

Adds a development dependency named gem with requirements to this gem.


spec.add_development_dependency 'example', '~> 1.1', '>= 1.1.4'

Development dependencies aren’t installed by default and aren’t activated when a gem is required.


Singular (alternative) writer for authors

Usage: = 'John Jones'


The path in the gem for executable scripts. Usually ‘exe’


spec.bindir = 'exe'


The certificate chain used to sign this gem. See Gem::Security for details.


Executables included in the gem.

For example, the rake gem has rake as an executable. You don’t specify the full path (as in bin/rake); all application-style files are expected to be found in bindir. These files must be executable Ruby files. Files that use bash or other interpreters will not work.

Executables included may only be ruby scripts, not scripts for other languages or compiled binaries.


spec.executables << 'rake'


Extensions to build when installing the gem, specifically the paths to extconf.rb-style files used to compile extensions.

These files will be run when the gem is installed, causing the C (or whatever) code to be compiled on the user’s machine.


spec.extensions << 'ext/rmagic/extconf.rb'

See Gem::Ext::Builder for information about writing extensions for gems.


Extra files to add to RDoc such as README or doc/examples.txt

When the user elects to generate the RDoc documentation for a gem (typically at install time), all the library files are sent to RDoc for processing. This option allows you to have some non-code files included for a more complete set of documentation.


spec.extra_rdoc_files = ['README', 'doc/user-guide.txt']


The platform this gem runs on.

This is usually Gem::Platform::RUBY or Gem::Platform::CURRENT.

Most gems contain pure Ruby code; they should simply leave the default value in place. Some gems contain C (or other) code to be compiled into a Ruby “extension”. The gem should leave the default value in place unless the code will only compile on a certain type of system. Some gems consist of pre-compiled code (“binary gems”). It’s especially important that they set the platform attribute appropriately. A shortcut is to set the platform to Gem::Platform::CURRENT, which will cause the gem builder to set the platform to the appropriate value for the system on which the build is being performed.

If this attribute is set to a non-default value, it will be included in the filename of the gem when it is built such as: nokogiri-1.6.0-x86-mingw32.gem


spec.platform = Gem::Platform.local


A message that gets displayed after the gem is installed.


spec.post_install_message = "Thanks for installing!"


Specifies the rdoc options to be used when generating API documentation.


spec.rdoc_options << '--title' << 'Rake -- Ruby Make' <<
  '--main' << 'README' <<


Paths in the gem to add to $LOAD_PATH when this gem is activated. If you have an extension you do not need to add "ext" to the require path, the extension build process will copy the extension files into “lib” for you.

The default value is "lib"


# If all library files are in the root directory...
spec.require_paths = ['.']


The version of Ruby required by this gem. The ruby version can be specified to the patch-level:

$ ruby -v -e 'p Gem.ruby_version'
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.0]
#<Gem::Version "">

Prereleases can also be specified.


# This gem will work with 1.8.6 or greater...
spec.required_ruby_version = '>= 1.8.6'

# Only with final releases of major version 2 where minor version is at least 3
spec.required_ruby_version = '~> 2.3'

# Only prereleases or final releases after 2.6.0.preview2
spec.required_ruby_version = '> 2.6.0.preview2'

# This gem will work with 2.3.0 or greater, including major version 3, but lesser than 4.0.0
spec.required_ruby_version = '>= 2.3', '< 4'


The RubyGems version required by this gem


The RubyGems version required by this gem


Lists the external (to RubyGems) requirements that must be met for this gem to work. It’s simply information for the user.


spec.requirements << 'libmagick, v6.0'
spec.requirements << 'A good graphics card'


The key used to sign this gem. See Gem::Security for details.