Ruby Gems Management
Installing and managing Ruby gems
Basic Gem Commands
gem install gem_name # install a gem
gem uninstall gem_name # remove a gem
gem list # list installed gems
gem update # update all gems
gem update gem_name # update specific gem
Gem Information
gem search keyword # search for gems
gem info gem_name # show gem details
gem which gem_name # show gem location
gem environment # show gem environment
Using Gems in Code
require 'gem_name' # load gem in Ruby file
require 'json' # load JSON gem
JSON.parse(string) # use gem functionality
Bundler
gem install bundler # install bundler
bundle init # create Gemfile
bundle install # install gems from Gemfile
bundle update # update all gems
bundle exec command # run command with bundler
Gemfile
source 'https://rubygems.org' # gem source
gem 'rails', '~> 7.0' # specify gem with version
gem 'pg' # add gem without version
group :development do # development-only gems
gem 'pry'
end