Open In App

How to Install Gems from Git Repositories?

Improve
Improve
Like Article
Like
Save
Share
Report

Rubygems is a package manager for the Ruby programming language. RubyGems provides a standard format to distribute Ruby programs and libraries, it is a tool designed to easily manage the installation of gems, and a server for distributing them. Git repositories contain project file tracks and save the versions of all the changes made to the files in the project. Git repositories can be cloned on a local machine for adding new features or for debugging purposes and changes were pushed to the origin in a git repository, it keeps track of the version and changes made in the files of the project.

Installing Gems from Git repository

Step 1: Clone the git repository.

  • Open git bash or terminal (in Linux) and run the following command  to clone the repository
  • If git bash is not installed on your system refer here.

git clone “url of the repository.*git”

Example,

git clone “https://github.com/dchelimsky/rspec.git”

Cloning-git-repo

 

Step 2: Change the directory to the cloned git repository.

  • Use the cd command to change the present working directory to the cloned git repository, and use the following command to change the directory.

cd ‘name of the git repo’

  • We are using RSpec repository so,

cd rspec

changed-directory-to-cloned-repository

 

Step 3: Build Gem.

  • The build command allows you to create a gem from a ruby gemspec. The gemspec can either be created by hand or extracted from an existing gem with gem spec.
  • Build the gem using the following command:

gem build gemname.gemspec -[OPTIONS]

Options

–platform PLATFORM – Specify the platform of gem to build

–force – skip validation of the spec

–strict – consider warnings as errors when validating the spec

-o, –output FILE – output gem with the given filename

-C PATH – Run as if gem build was started in instead of the current working directory.

  • Note: Don’t forget to change the name of the gem according to your repository, in this tutorial we are working on rspec repository, and here gem name is defined as rspec.gemspec so the command goes like the following.

gem build rspec.gemspec

Build-gem

 

Step 4: Install the gem.

  • To install the gem command goes like following

gem install [options] gemname-version.gem

Options:

-h, –help – To help on this command

-V, –[no-]verbose – To Set the verbose level of output

-q, –quiet – Silence command progress meter

–silent – Silence RubyGems output

–config-file FILE – Use config file instead of default

–backtrace – Show stack backtrace on errors

–debug – Turn on Ruby debugging

–norc – Avoid loading any .gemrc file

  • Note: Replace the gemname with the name of the gem and version with its version, in this tutorial gem name is rspec and its version is 1.3.2 so the command will be,

gem install rspec-1.3.2.gem

  • Note: If you are working on a Linux terminal you might encounter a File Permission Error, so to overcome that run the command as sudo.

sudo gem install respc-1.3.2.gem

Installed-gem-successfully

 

Conclusion

  • Step 1: Clone the repository.

git clone “URL of  repository”.git

cloning-repository

 

  • Step 2: Change the directory to the cloned repository.

cd “Name of the repository”

changing-directory

 

  • Step 3: Build the gem.

gem build gemname.gemspec [OPTIONS]

building-gem

 

  • Step 4: Install the gem.

gem install [OPTIONS] gemname-version.gem

installing-gem

 


Last Updated : 27 Dec, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads