Getting Started
Guides
Dependency Management
- How to manage application dependencies with Bundler
- How to manage dependencies with Bundler
- How to update gems with Bundler
- How to manage groups of gems
- How to install gems from git repositories
- How to develop multiple gems in one repository
- How to use Bundler with Ruby
- How to use Bundler in a single-file Ruby script
- How to deploy bundled applications
Gem Development
Publishing & Security
- Trusted Publishing
- Setting up multi-factor authentication
- Using multi-factor authentication in command line
- Managing owners using UI
- Organizations
- Removing a Published gem
- Security Practices
- How to delay new gem versions with cooldown
Integrations
- How to use Bundler with Rails
- How to use Bundler with Sinatra
- How to use Bundler with Docker
- How to use Bundler in CI
Hosting & Sources
Extending
Troubleshooting
- Troubleshooting common issues
- How to troubleshoot RubyGems and Bundler TLS/SSL Issues
- How to use git bisect with Bundler
Concepts
- What is a gem?
- Gemfile and gemspec
- Where gems are installed and how they load
- How dependency resolution works
- How Gemfile.lock works
- Versioning and compatibility
- Platforms and native gems
- Caching and vendoring
- Default gems and bundled gems
- Common Vulnerabilities and Exposures
Reference
- gem Command Reference
- Bundler Command Reference
- Gemfile Reference
- Ruby Directive
- Specification Reference
- RubyGems.org API
- RubyGems.org Compact Index API
- RubyGems.org rate limits
- API key scopes
- Bundler compatibility with Ruby
- Configuration (.gemrc)
- Environment variables
- Known Bundler Plugins
Appendix
What is a gem?
Unpack the mystery behind what’s in a RubyGem.
Structure of a Gem
Each gem has a name, version, and platform. For example, the
rake gem has a 13.0.6 version (from Jul
2021). Rake’s platform is ruby, which means it works on any platform Ruby
runs on.
Platforms are based on the CPU architecture, operating system type and
sometimes the operating system version. Examples include “x86-mingw32” or
“java”. The platform indicates the gem only works with a ruby built for the
same platform. RubyGems will automatically download the correct version for
your platform. See gem help platform for full details.
Inside gems are the following components:
- Code (including tests and supporting utilities)
- Documentation
- gemspec
Each gem follows the same standard structure of code organization:
% tree freewill
freewill/
├── bin/
│ └── freewill
├── lib/
│ └── freewill.rb
├── test/
│ └── test_freewill.rb
├── README
├── Rakefile
└── freewill.gemspec
Here, you can see the major components of a gem:
- The
libdirectory contains the code for the gem - The
testorspecdirectory contains tests, depending on which test framework the developer uses - A gem usually has a
Rakefile, which the rake program uses to automate tests, generate code, and perform other tasks. - This gem also includes an executable file in the
bindirectory, which will be loaded into the user’sPATHwhen the gem is installed. - Documentation is usually included in the
READMEand inline with the code. When you install a gem, documentation is generated automatically for you. Most gems include RDoc documentation, but some use YARD docs instead. - The final piece is the gemspec, which contains information about the gem. The gem’s files, test information, platform, version number and more are all laid out here along with the author’s email and name.
More information on the gemspec file
The Gemspec
The gemspec specifies the information about a gem such as its name, version, description, authors and homepage.
Here’s an example of a gemspec file. You can learn more in how to make a gem.
% cat freewill.gemspec
Gem::Specification.new do |s|
s.name = 'freewill'
s.version = '1.0.0'
s.summary = "Freewill!"
s.description = "I will choose Freewill!"
s.authors = ["Nick Quaranto"]
s.email = 'nick@quaran.to'
s.homepage = 'http://example.com/freewill'
s.files = ["lib/freewill.rb", ...]
end
For more information on the gemspec, please check out the full Specification Reference which goes over each metadata field in detail.
Credits
This guide was adapted from Gonçalo Silva’s original tutorial on docs.rubygems.org and from Gem Sawyer, Modern Day Ruby Warrior.