Open In App

How to Install Gems from Gemfile in Ruby?

Improve
Improve
Like Article
Like
Save
Share
Report

Ruby is a dynamic and object-oriented, general-purpose programming language. Ruby’s development was to make it act as a sensible buffer between human programmers and the underlying computing machinery. Basically, Ruby gems are open-source libraries that contain codes packaged with data. By using a gem, programmers can use the code within the gem in their own program. 

Steps to Install Gems from Gemfile in Ruby

If you do not have Ruby on your computer you can refer to this article install Ruby. After installing the ruby programming language now we install the ruby gems from gemfile. Follow the steps to install Ruby Gems from Gemfile:

Step 1: Open the terminal and write gem install “gemname”, for example, gem install abc.

 gem install “gemname”

gem-install-command

 

Step 2: Bundler provides a consistent environment for Ruby projects by tracking and installing the needed gems and versions. Now we install Bundler using the command.

 gem install bundler 

Installing-bundler

 

Step 3: Now initializes the bundle using the init function, If you are getting an error in the terminal you can open any code editor in that folder in which the bundle installs and initializes the root directory.

bundle init

Initializing-bundle

 

Step 4: Bundler is a gem that manages dependencies. It creates an environment for Ruby projects. Now open the root directory and create Gemfile. Now open the Gemfile with the code editor and Specify the dependencies in a Gemfile.

source ‘https://rubygems.org’
gem ‘multi_json’
gem ‘rack’
gem ‘rspec’
gem  ‘watir’
 

Specifying-dependencies

 

Step 5: Now the install is required gems from the above sources by using the command in the code editor terminal.

bundle install

Bundle-install

 

Step 6: To verify gems installed, write the command in the terminal that gives the full list of gems installed in your computer.

gem list

Verifying-gems

 


Last Updated : 04 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads