Gems and Bundler

Contents
gem install
The Gemfile
Bundle install
The lockfile

gem install

A gem is a packaged Ruby library with code and metadata. The gem command installs and lists these packages on your machine.

Check the tool itself first, then install one package by name to try it out quickly in a script.

gem -v

3.5.11

gem install minitest

Successfully installed minitest-5.20.0

The Gemfile

The Gemfile lists the gems one project needs, with optional version limits. Bundler reads it to build a consistent set.

Keep this file in version control so every machine installs the same stack. The idioms from Duck typing and core idioms stay the same no matter which gems you add.

source "https://rubygems.org" gem "minitest", "~> 5.20"

Bundle install

bundle install reads the Gemfile and installs every missing gem. Run it after cloning a project and after editing the Gemfile.

Bundler resolves versions so all gems fit together, then remembers the result for the next section.

bundle -v

Bundler version 2.5.11

bundle install

Bundle complete

The lockfile

Bundler writes exact versions into Gemfile.lock. This file freezes the whole tree, including dependencies of dependencies.

Commit the lockfile for apps so servers and teammates run identical code. Libraries usually leave it out because they support version ranges. More Ruby tooling is linked from the Ruby overview.

GEM specs: minitest (5.20.0)

Next: Testing with Minitest

Article author: Arthur Isaev

Related articles
Ruby
Ruby course: zero to hero in 50 lessons
What is Ruby and where it runs
Install Ruby and check the version
irb: the interactive shell
Your first Ruby script
Variables
Numbers
Strings
Symbols
Truthiness: only false and nil
Conditions
Loops
Arrays
Hashes
Ranges
Methods
Blocks, procs, lambdas
String tools
Files and IO
Exceptions
Modules and mixins
Classes and objects
Inheritance
Enumerables
Duck typing and core idioms
Gems and Bundler
Testing with Minitest
Debugging
Encodings
Time and date
JSON and YAML
HTTP clients
Sockets
REST APIs
puts, print and p
Metaprogramming
Enumerators
Pattern matching
Arguments: splats and kwargs
Rake tasks
Environment and CLI
Logging
CSV
ERB templates
WEBrick server
Rails in one lesson
Capstone: todo CLI
Capstone: JSON API
Performance
Modern Ruby tour
Hero roadmap: the whole course on one page
Install Ruby on Windows 11
Install Ruby on Ubuntu
Install Ruby on Rocky Linux
Install Ruby on macOS
Install Ruby on FreeBSD
Ruby in Docker
Threads and fibers
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: