RubyMine 2026.1 Help

Create and publish your first Ruby gem

This tutorial shows how to create a simple Ruby gem in RubyMine and publish it to RubyGems.org.

Before you start:

Create a Gem application

To create a new Gem application, follow the steps below:

  1. Run RubyMine and click New Project on the Welcome Screen.

    Welcome screen
  2. In the New Project dialog, select Gem on the left pane and specify the following settings:

    New Project dialog / Gem
    • Location: Specify a project's location and name (hello_rubymine in our case).

    • Interpreter: Select a required Ruby interpreter.

    After you’ve specified all the options, click Create in the New Project dialog. RubyMine will create a new Gem application.

Add code

Code for gems is placed within the lib directory. Our newly created project contains the hello_rubymine.rb file in this folder. Let's add working code for our gem:

  1. To open hello_rubymine.rb, press Ctrl+Shift+N, start typing hello_rubymine.rb, select this file, and press Enter.

  2. In the opened lib/hello_rubymine.rb file, add the following code:

    require "hello_rubymine/version" module HelloRubymine def self.greet(name) puts "Hello, #{name}! I'm Ruby!" end end

Provide gem specification

Every gem project has the *.gemspec file containing information for a gem. In our project, this information is stored in the hello_rubymine.gemspec file. Perform the following steps to provide the required data:

  1. Press Ctrl+Shift+N, start typing hello_rubymine.gemspec, select the hello_rubymine.gemspec file, and press Enter

  2. In the opened hello_rubymine.gemspec file, specify the required gemspec attributes.

    Gemspec file

    For the sample gem,specify the following fields:

    • authors: A gem's author(s).

    • email: An email address.

    • summary: A short gem's description

    • homepage: The URL of the gem's home page. We'll specify this address later after publishing the gem's code to GitHub.

    • metadata["source_code_uri"]: The gem's source code URI. We'll use the same value as for the homepage.

Share gem on GitHub

In this section, publish the gem source code to GitHub:

  1. Go to Git | Share Project on GitHub.

  2. In the invoked dialog, specify the name of the repository to be created on GitHub. Then, select the required account in the Share by field and click the Share button.

    Share project on GitHub dialog
  3. In the next dialog, you will be prompted to choose files for the initial commit. Leave the default set of files, specify the commit message, and click Add. Wait until the project is pushed to GitHub.

  4. After the project is created on GitHub, provide the homepage and metadata["source_code_uri"] attributes in the project's *.gemspec file (https://github.com/rubyminedoc/hello_rubymine in our case). Then, commit and push changes made in *.gemspec.

Build gem

After you've specified the gem information in the *.gemspec file, build the gem.

  1. Open the terminal and run the following command in the project root directory:

    gem build hello_rubymine.gemspec
  2. After the command completes, the .gem file will be created in the project directory.

Install gem

After building a gem, we can install it to a local interpreter for testing:

  • Press Ctrl twice and enter the following command:

    gem install hello_rubymine

    Press Enter to install a gem.

Test gem with IRB

In this chapter, we'll test our gem using the IRB console by calling it's greet method:

  1. In the main menu, go to Tools | Run IRB Console.

  2. Type require 'hello_rubymine' and press Enter to load our gem to IRB.

  3. Then, type HelloRubymine.greet("JetBrains") in a console and press Enter again to make sure our gem works as expected.

    Test gem in IRB console

Publish gem

Make sure you have a RubyGems account and your credentials are configured.

  1. Run the following command:

    gem push hello_rubymine-0.1.0.gem
  2. After the command completes, your gem will be published to RubyGems.

20 March 2026