# Create and publish your first Ruby gem

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/ruby/2026.3/llms.txt).

> **TL;DR**
> Completed project: [hello_rubymine](https://github.com/rubyminedoc/hello_rubymine)

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

Before you start:

* Install [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).

* [Register](set-up-a-github-account.html#register-account) your GitHub account in RubyMine.

* Install the [Ruby distribution](set-up-a-ruby-development-environment.html#ruby) for your platform.

## Create a Gem application

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

Procedure:

1. Run RubyMine and click New Project on the [Welcome Screen](null).

![Welcome screen](https://resources.jetbrains.com/help/img/idea/2026.3/rm_welcome_screen_empty.png)

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

![New Project dialog / Gem](https://resources.jetbrains.com/help/img/idea/2026.3/rm_create_gem_new_project_dialog.png)

* Location: Specify a project's location and name (hello_rubymine in our case).

* Interpreter: Select a required Ruby interpreter.

> **Note:**
> If the Bundler gem is not installed to the selected interpreter, RubyMine will automatically install it upon the project creation.

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](#create_gem) project contains the `hello_rubymine.rb` file in this folder. Let's add working code for our gem:

Procedure:

1. To open `hello_rubymine.rb`, press `Ctrl+Shift+N` (Windows), `⌘ ⇧ O` (macOS), `⌘ ⇧ N` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ O` (macOS System Shortcuts), `Ctrl+Shift+N` (XWin), `Ctrl+Shift+N` (GNOME), `Ctrl+Shift+N` (KDE), `Ctrl+X, Ctrl+F` (Emacs), `Ctrl+P` (Sublime Text), `⌘ P` (Sublime Text (macOS)), `Ctrl+Shift+T` (Visual Studio), `⌘ ⇧ T` (Visual Studio (macOS)), `Meta+T` (TextMate), `Alt+Shift+O` (NetBeans), `Ctrl+Shift+R` (Eclipse), `⌘ ⇧ R` (Eclipse (macOS)), start typing hello_rubymine.rb, select this file, and press `Enter` (Windows), `⏎` (macOS), `⏎` (IntelliJ IDEA Classic (macOS)), `⏎` (macOS System Shortcuts), `Enter` (XWin), `Enter` (GNOME), `Enter` (KDE), `Enter` (Emacs), `Enter` (Sublime Text), `⏎` (Sublime Text (macOS)), `Enter` (Visual Studio), `⏎` (Visual Studio (macOS)), `Enter` (TextMate), `Enter` (NetBeans), `Enter` (Eclipse), `⏎` (Eclipse (macOS)).

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

```RUBY
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:

Procedure:

1. Press `Ctrl+Shift+N` (Windows), `⌘ ⇧ O` (macOS), `⌘ ⇧ N` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ O` (macOS System Shortcuts), `Ctrl+Shift+N` (XWin), `Ctrl+Shift+N` (GNOME), `Ctrl+Shift+N` (KDE), `Ctrl+X, Ctrl+F` (Emacs), `Ctrl+P` (Sublime Text), `⌘ P` (Sublime Text (macOS)), `Ctrl+Shift+T` (Visual Studio), `⌘ ⇧ T` (Visual Studio (macOS)), `Meta+T` (TextMate), `Alt+Shift+O` (NetBeans), `Ctrl+Shift+R` (Eclipse), `⌘ ⇧ R` (Eclipse (macOS)), start typing hello_rubymine.gemspec, select the `hello_rubymine.gemspec` file, and press `Enter` (Windows), `⏎` (macOS), `⏎` (IntelliJ IDEA Classic (macOS)), `⏎` (macOS System Shortcuts), `Enter` (XWin), `Enter` (GNOME), `Enter` (KDE), `Enter` (Emacs), `Enter` (Sublime Text), `⏎` (Sublime Text (macOS)), `Enter` (Visual Studio), `⏎` (Visual Studio (macOS)), `Enter` (TextMate), `Enter` (NetBeans), `Enter` (Eclipse), `⏎` (Eclipse (macOS))

2. In the opened `hello_rubymine.gemspec` file, specify the required [gemspec attributes](https://guides.rubygems.org/specification-reference/).

![Gemspec file](https://resources.jetbrains.com/help/img/idea/2026.3/rm_create_gem_gemspec_editor.png)

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](#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:

Procedure:

1. Go to `Git | GitHub | 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](https://resources.jetbrains.com/help/img/idea/2026.3/rm_create_gem_share_project_gihub_dialog.png)

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](commit-and-push-changes.html) changes made in `*.gemspec`.

## Build gem

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

Procedure:

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

```BASH
gem build hello_rubymine.gemspec
```

2. After the command completes, the `.gem` file will be created in the project directory.

## Install gem

After [building](#build) a gem, we can install it to a [local interpreter](configuring-language-interpreter.html) for testing:

Procedure:

* Press `Ctrl` (Windows), `Ctrl` (macOS), `Ctrl` (IntelliJ IDEA Classic (macOS)), `Ctrl` (macOS System Shortcuts), `Ctrl` (XWin), `Ctrl` (GNOME), `Ctrl` (KDE), `Ctrl` (Emacs), `Ctrl` (Sublime Text), `Ctrl` (Sublime Text (macOS)), `Ctrl` (Visual Studio), `Ctrl` (Visual Studio (macOS)), `Ctrl` (TextMate), `Ctrl` (NetBeans), `Ctrl` (Eclipse), `Ctrl` (Eclipse (macOS)) 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](running-console.html) console by calling its `greet` method:

Procedure:

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](https://resources.jetbrains.com/help/img/idea/2026.3/rm_create_gem_irb_console.png)

## Publish gem

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

Procedure:

1. Run the following command:

```BASH
gem push hello_rubymine-0.1.0.gem
```

2. After the command completes, your gem will be published to RubyGems.

> **Note:**
> RubyMine does not provide dedicated actions for building or publishing gems. Use the standard RubyGems CLI workflow instead.

