Installation of Custom Gem File into your Ruby Project
By Vishnuram R — “The Creative Dreamer”
The package could include Ruby applications and libraries, saved as a “Filename.gem” (in a self-contained format) format. Each gem has a name, version, and platform. Platforms are determined by the type of operating system, the Processor architecture, and occasionally the operating system version. The platform indicates the gem only works with a ruby built for the same platform. The appropriate version for your platform will be downloaded automatically by RubyGems.
The Ruby Gem file can be a custom gem file that you can create or we can install a gem using the gem install command which downloads and installs the gem and necessary dependencies. You can also install specific versions of the package by including -v in your command line.
$gem install “gem package name” -v “Version number”
You can check whether the gem is installed by using the list command which lists the locally installed gem, there you can check whether the required gem is installed.
You can Uninstall a gem using uninstall command which helps to uninstall a gem library you specified and you can also uninstall a specific gem version by including -v in your command line
$gem uninstall “package name” -v “Version number”
• bin Directory contains an executable file, which will be loaded into the user’s PATH when the gem is installed.
• lib Directory contains the code for the gem
• The Rakefile, which the rake program uses to automate tests, generate code, and perform other tasks.
• The README File contains the Documentation of the gem. Most gems include RDoc documentation, but some use YARD documentation also.
• The gemspec, which contains information about the gem. The gem’s files, test information, platform, version number, and more are all present here along with the author’s email and name.
• test Directory contains the test code for the gem whether it works and does its job
A Custom Gem can be installed in your Ruby Project in 3 Different Ways
The Gem file can be installed using GitHub sources. You can specify the gem name and path of the GitHub source in the GemFile and install them using the git install command or bundle install
gem ‘rails_admin’, :git => ‘git://github.com/sferik/rails_admin.git’
When you are trying to install a gem from an unreachable source you cannot install the gem using bundle install. You can follow these steps to install the gem from GitHub sources
• Download the files from the GitHub source
• Place the files in a Directory in your Ruby Project
• Add the gem name and path to your Gemfile,
gem ‘rails_admin’, :path => “vendor/gems/rails_admin”
• Run Bundle Install and you can find the gem is being installed in your Ruby Project. You can verify by listing the installed gem ($gem list)
You can publish your gem file to RubyGems.org and install the gem to your Ruby program. You can do this by following the steps:
• After setting up in your computer, you can publish the gem to RubyGems.org by executing the command $gem push “Filename”.gem
• After publishing the gem to RubyGem.org your gem will be available to install by anyone.
• Then you can use $gem install “gem name” and install the gem to your Ruby program.
If you have a .gem file downloaded locally on your computer then you can install the gem file by following the steps
• First place your .gem file in a directory of your Ruby program after downloading them locally on your computer.
• Navigate to the Directory where you have placed your .gem file after downloading
• Execute command $gem unpack “Filename”.gem
• After executing the command without throwing any errors you can find a directory similar to the file name of the .gem file.
• Inside the directory you can find the list of components that are present in the .gem file
• Then you must add the gem name and path in the Gemfile(File that is created to describe the gem dependencies required to run a Ruby program) of your Ruby program.
• You can install this gem by $gem install “gem name” or $bundle install to install the gem to your Ruby program.
. You can check whether the gem is installed properly by listing them $gem list
Ruby Programming Language is widely used in different fields of development and with lots of features available for easy integration and feature development. RubyGems are libraries or Packages which are used in development of new features and these packages can be custom developed packages by an individual or organisation and can be installed by following any of the methods mentioned in the article.
We at CaratLane are solving some of the most intriguing challenges to make our mark in the relatively uncharted omnichannel jewellery industry. If you are interested in tackling such obstacles, feel free to drop your updated resume/CV to firstname.lastname@example.org!