A RubyGem, commonly called just a gem, is a packaged Ruby library, which installation allows you use the functionality of a common library in your application. This tutorial is meant to explain how to create and deploy a RubyGem.

0. Prerequisites

Make sure the following prerequisites are met:

1. Creating a New Gem App

Creating a new gem can be done by going to

{span:class=shortcut}File \| New Project...{span}
and choosing
{span:class=shortcut}Ruby Gem{span}
. Specify location and name of the project, then choose Ruby SDK supposed to be used for the project and set
{span:class=shortcut}Create bin folder{span}
{span:class=shortcut}Create test folder{span}
if these folders are required to be generated for the project:

The skeleton of the application is automatically generated:

2. Configuring Git Root

Unregistered Git root notification appears as soon as the application structure is ready:


or go to
{span:class=shortcut}Settings \-> Version Control{span}
and add application root to version control if required:

3. Adding Working Code

Navigate to the main module (

) and add the code expected to be doing something:

Then navigate to Gemspec file (

) and set up the summary and description sections:

4. Building Gem

Go to the

{span:class=shortcut}Tools \| Gem{span}
menu and select
{span:class=shortcut}Build Gem{span}
option. After the gem is built a file with the gem extension can be found in the project view:

5. Installing Gem Locally

Before being uploaded to RubyGems repository the gem needs to be tested, so lets install the gem. Go to

{span:class=shortcut}Run \| Edit Configurations...{span}
and add a new
{span:class=shortcut}Gem Command{span}
as described:

Apply the changes and run the configuration (

), wait for the gem being installed:

6. Smoke Testing with IRB

To test the gem run IRB console (

{span:class=shortcut}Tools \| Run IRB Console...{span}
) and call the methods of the newly installed gem:

7. Gem Publishing

RubyMine uses RubyGems.org as a default gem repository. If it is the first time you're publishing your gem, make sure you are signed up to RubyGems and your credentials are set. Read more in RubyGems guides.

Gem can now be pushed with

{span:class=shortcut}Tools \| Gem \-> Push Gem{span}

If you want to use your own gem repository, please change your .gemspec file according to RubyGems guides:

Gem::Specification.new 'develop_with_pleasure' do |spec|
  # ...
  spec.metadata['allowed_push_host'] = 'https://gems.my-company.example'