A RubyGems repository is a place where Ruby libraries (called gems) are stored and shared. It helps you find and use code others wrote, so you don't have to build everything from scratch.
0
0
RubyGems repository
Introduction
When you want to add new features to your Ruby program without writing all the code yourself.
When you want to share your own Ruby code with others easily.
When you need to manage and install external libraries for your Ruby projects.
When you want to keep your project's dependencies organized and up to date.
Syntax
Ruby
gem install <gem_name> # To use a gem in your Ruby file: require '<gem_name>'
gem install downloads and installs a gem from the RubyGems repository.
require loads the gem in your Ruby program so you can use its features.
Examples
This command installs the popular Rails gem from the RubyGems repository.
Ruby
gem install rails
This code uses the built-in JSON gem to convert a Ruby hash into a JSON string.
Ruby
require 'json' puts JSON.generate({name: 'Alice', age: 30})
Installs and loads Nokogiri, a gem for parsing HTML and XML.
Ruby
gem install nokogiri require 'nokogiri'
Sample Program
This program installs the colorize gem, loads it, and prints the text 'Hello, world!' in blue color in the terminal.
Ruby
gem install colorize require 'colorize' puts 'Hello, world!'.colorize(:blue)
OutputSuccess
Important Notes
You need an internet connection to install gems from the RubyGems repository.
Once installed, gems are saved on your computer and can be used anytime without reinstalling.
Use gem list to see all gems installed on your system.
Summary
RubyGems repository stores and shares Ruby libraries called gems.
You install gems using gem install and use them with require.
Gems save you time by letting you reuse code others wrote.