Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Gem::Specification#license=

license=(o)

The license for this gem.

The license must be no more than 64 characters, and should be a single SPDX license identifier from spdx.org/licenses/. Ideally, you should pick one that is OSI (Open Source Initiative) opensource.org/licenses/ approved.

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

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

RubyGems validates the license against the SPDX license list when you run gem build and warns about unknown or deprecated identifiers. An identifier may carry a trailing + (this version or any later version) and a license exception joined with WITH, for example Apache-2.0 WITH LLVM-exception.

Compound SPDX license expressions such as MIT OR Apache-2.0 are not currently supported. RubyGems treats the whole string as a single identifier and warns that it is invalid. For a gem available under more than one license, set each license as a separate entry with licenses=.

For a license that has no SPDX identifier, use Nonstandard, or 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.

Usage:

Example
spec.license = 'MIT'
See also #license #licenses #lib_files #licenses= also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0