- RubyGems Basics
- What is a gem?
- Make your own gem
- Gems with Extensions
- Name your gem
- Publishing your gem
- Security Practices
- Managing owners using UI
- Removing a Published gem
- SSL Certificate Update
- Patterns
- Specification Reference
- Command Reference
- RubyGems.org API
- RubyGems.org API V2.0
- RubyGems.org Compact Index API
- RubyGems.org rate limits
- API key scopes
- Run your own gem server
- Setting up multi-factor authentication
- Using multi-factor authentication in command line
- MFA requirement opt in
- Using S3 as gem source
- Default gems and bundled gems
- Resources
- Contributing to RubyGems
- Frequently Asked Questions
- Plugins
- Common Vulnerabilities and Exposures
- Trusted Publishing
- Organizations
- Credits
Bundler
- Bundler in gems
- Gemfiles
- Getting Started
- How to Upgrade to Bundler 2
- How to deploy bundled applications
- How to install gems from git repositories
- How to manage application dependencies with Bundler
- How to manage groups of gems
- How to manage dependencies with Bundler
- How to troubleshoot RubyGems and Bundler TLS/SSL Issues
- How to update gems with Bundler
- How to use Bundler in a single-file Ruby script
- How to use Bundler with Docker
- How to use Bundler with Rails
- How to use Bundler with Ruby
- How to use Bundler with RubyMotion
- How to use Bundler with Sinatra
- How to use git bisect with Bundler
- How to write a Bundler plugin
- Known Plugins
- Recommended Workflow with Version Control
- Ruby Directive
Ruby Directive
Specifying a Ruby Version
Like gems, developers can setup a dependency on Ruby.
This makes your app fail faster in case you depend on specific features in a Ruby VM.
This way, the Ruby VM on your deployment server will match your local one. You can do this by using the ruby directive in the Gemfile:
ruby 'RUBY_VERSION', :engine => 'ENGINE', :engine_version => 'ENGINE_VERSION',
:patchlevel => 'RUBY_PATCHLEVEL'
If you wanted to use JRuby 9.4.10.0 using Ruby 3.1.4, you would simply do the following:
ruby '3.1.4', :engine => 'jruby', :engine_version => '9.4.10.0'
It’s also possible to restrict the patchlevel of the Ruby used by doing the following:
ruby '3.3.6', :patchlevel => '108'
If you wish to derive your Ruby version from a version file (i.e. .ruby-version),
you can use the file option instead.
ruby file: ".ruby-version"
The version file should conform to any of the following formats:
3.1.2(.ruby-version)ruby-3.1.2(.ruby-version)ruby 3.1.2(.tool-versions)ruby = '3.1.2'(mise.toml)
Bundler will make checks against the current running Ruby VM to make sure it matches what is specified in the Gemfile. If things don’t match, Bundler will raise an Exception explaining what doesn’t match.
Your Ruby version is 3.3.7, but your Gemfile specified 3.4.1
Both :engine and :engine_version are optional.
When these options are omitted, this means the app is compatible with a particular Ruby ABI but the engine is irrelevant.
When :engine is used, :engine_version must also be specified.
Using the platform command with the --ruby flag, you can see what ruby directive is specified in the Gemfile.
ruby 3.1.4p0 (jruby 9.4.10.0)
In the ruby directive, :patchlevel is optional, as patchlevel releases are usually compatible and include important security fixes.
The patchlevel option checks the RUBY_PATCHLEVEL constant, and if not specified then bundler will simply ignore it.
Version operators for specifying a Ruby version are also available.
The set of supported version operators is that of Rubygems (gem version operators). (ie. <, >, <=, >=, ~>, =)
ruby '~> 3.3.0'