Ruby, Gem, Bundler
Published:
What are Ruby, Gem, Bundler?
Think of the Ruby world as three stacked Lego bricks:
- Ruby itself – the language runtime (the “engine”).
- Gem – Ruby’s single-library package manager (one brick at a time).
- Bundler – the project-level multi-library resolver (the whole Lego set for one project).
Below is the long-form tour.
Ruby
An interpreted, object-oriented scripting language (like Python, Perl, Lua). Ships with a small standard library (File, Net::HTTP, JSON, etc.). Anything not in the standard library has to be installed separately → enter “gems”.
Gem
A gem is a plain *.gem file: code + metadata (name, version, author, dependencies).
gem install rails downloads the rails gem and its dependencies.
- To install into the user local directory(
~/.local/share/gem/ruby/3.4.0/gems), usegem install. - To install into the system wide direcotry(
/usr/lib/ruby/gems/3.4.0/gems), usegem --no-user-install install bundler.
NOTE: You can check environment variables related to Gem by gem env.
Bundler (bundle, bundler)
Bundler is itself a gem (can be installed by gem install bundler).
It adds a project layer: every project gets its own Gemfile that declares exact gems + versions it needs.
Running bundle install:
– computes a full dependency graph, – writes the exact snapshot to Gemfile.lock, – downloads missing gems, – can optionally keep them inside the project (vendor/bundle) or in a shared path by bundle config set --local path 'vendor/bundle'
Typical workflow
- Install ruby & bundler
ruby -v # make sure Ruby is installed gem install bundler # one-time global install - Edit Gemfile
bundle init # creates an empty Gemfile
bundle init will create an empty Gemfile.
source 'https://rubygems.org'
gem 'jekyll', '~> 4.3'
gem 'rake', '~> 13.0'
- Install Gems
bundle install # resolves & installs
bundle install will resolve depedencies and create gems.
Locked gems will be written in Gemfile.lock.
- Run with locked gems
bundle exec jekyll serve # run with locked gems
